diff --git a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs
index 7280c7618c..a59767c0f8 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/MessageComponents/RestMessageComponent.cs
@@ -141,8 +141,7 @@ public override string Respond(
///
/// A delegate containing the properties to modify the message with.
/// The request options for this request.
- /// A string that contains json to write back to the incoming http request.
- public string Update(Action func, RequestOptions options = null)
+ public async Task UpdateAsync(Action func, RequestOptions options = null)
{
var args = new MessageProperties();
func(args);
@@ -200,20 +199,43 @@ public string Update(Action func, RequestOptions options = nu
}
}
- var response = new API.InteractionResponse
+ if (!args.Attachments.IsSpecified)
{
- Type = InteractionResponseType.UpdateMessage,
- Data = new API.InteractionCallbackData
+ var response = new API.InteractionResponse
+ {
+ Type = InteractionResponseType.UpdateMessage,
+ Data = new API.InteractionCallbackData
+ {
+ Content = args.Content,
+ AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
+ Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
+ Components = args.Components.IsSpecified
+ ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
+ : Optional.Unspecified,
+ Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
+ }
+ };
+
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
+ }
+ else
+ {
+ var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty();
+
+ var response = new API.Rest.UploadInteractionFileParams(attachments)
{
+ Type = InteractionResponseType.UpdateMessage,
Content = args.Content,
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
- Components = args.Components.IsSpecified
+ MessageComponents = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
: Optional.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
- }
- };
+ };
+
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
+ }
lock (_lock)
{
@@ -221,11 +243,9 @@ public string Update(Action func, RequestOptions options = nu
{
throw new InvalidOperationException("Cannot respond, update, or defer twice to the same interaction");
}
-
- HasResponded = true;
}
- return SerializePayload(response);
+ HasResponded = true;
}
///
@@ -493,7 +513,7 @@ public override string RespondWithModal(Modal modal, RequestOptions options = nu
///
Task IComponentInteraction.UpdateAsync(Action func, RequestOptions options)
- => Task.FromResult(Update(func, options));
+ => UpdateAsync(func, options);
///
Task IComponentInteraction.DeferLoadingAsync(bool ephemeral, RequestOptions options)
diff --git a/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs b/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs
index 37abc22dba..33220d8841 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/Modals/RestModal.cs
@@ -512,20 +512,43 @@ public async Task UpdateAsync(Action func, RequestOptions opt
}
}
- var response = new API.InteractionResponse
+ if (!args.Attachments.IsSpecified)
{
- Type = InteractionResponseType.UpdateMessage,
- Data = new API.InteractionCallbackData
+ var response = new API.InteractionResponse
+ {
+ Type = InteractionResponseType.UpdateMessage,
+ Data = new API.InteractionCallbackData
+ {
+ Content = args.Content,
+ AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
+ Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
+ Components = args.Components.IsSpecified
+ ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
+ : Optional.Unspecified,
+ Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
+ }
+ };
+
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
+ }
+ else
+ {
+ var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty();
+
+ var response = new API.Rest.UploadInteractionFileParams(attachments)
{
+ Type = InteractionResponseType.UpdateMessage,
Content = args.Content,
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
- Components = args.Components.IsSpecified
+ MessageComponents = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
: Optional.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
- }
- };
+ };
+
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
+ }
lock (_lock)
{
@@ -535,7 +558,6 @@ public async Task UpdateAsync(Action func, RequestOptions opt
}
}
- await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
HasResponded = true;
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs
index 8758b98788..6691bc6e1d 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/MessageComponents/SocketMessageComponent.cs
@@ -286,7 +286,9 @@ public async Task UpdateAsync(Action func, RequestOptions opt
}
else
{
- var response = new API.Rest.UploadInteractionFileParams(args.Attachments.Value.ToArray())
+ var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty();
+
+ var response = new API.Rest.UploadInteractionFileParams(attachments)
{
Type = InteractionResponseType.UpdateMessage,
Content = args.Content,
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs
index 20daf7a059..ff1d4dc81c 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Modals/SocketModal.cs
@@ -258,20 +258,43 @@ public async Task UpdateAsync(Action func, RequestOptions opt
}
}
- var response = new API.InteractionResponse
+ if (!args.Attachments.IsSpecified)
{
- Type = InteractionResponseType.UpdateMessage,
- Data = new API.InteractionCallbackData
+ var response = new API.InteractionResponse
+ {
+ Type = InteractionResponseType.UpdateMessage,
+ Data = new API.InteractionCallbackData
+ {
+ Content = args.Content,
+ AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
+ Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
+ Components = args.Components.IsSpecified
+ ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
+ : Optional.Unspecified,
+ Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
+ }
+ };
+
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
+ }
+ else
+ {
+ var attachments = args.Attachments.Value?.ToArray() ?? Array.Empty();
+
+ var response = new API.Rest.UploadInteractionFileParams(attachments)
{
+ Type = InteractionResponseType.UpdateMessage,
Content = args.Content,
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
- Components = args.Components.IsSpecified
+ MessageComponents = args.Components.IsSpecified
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
: Optional.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
- }
- };
+ };
+
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
+ }
lock (_lock)
{
@@ -281,7 +304,6 @@ public async Task UpdateAsync(Action func, RequestOptions opt
}
}
- await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
HasResponded = true;
}