feat: Add support for attachments on interaction response type 7 (#2336)
* Add support for attachments on interaction response type 7 * Add missing checks
This commit is contained in:
@@ -226,8 +226,12 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(Message.Content);
|
bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(Message.Content);
|
||||||
bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || Message.Embeds.Any();
|
bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || Message.Embeds.Any();
|
||||||
|
bool hasComponents = args.Components.IsSpecified && args.Components.Value != null;
|
||||||
|
bool hasAttachments = args.Attachments.IsSpecified;
|
||||||
|
bool hasFlags = args.Flags.IsSpecified;
|
||||||
|
|
||||||
if (!hasText && !hasEmbeds)
|
// No content needed if modifying flags
|
||||||
|
if ((!hasComponents && !hasText && !hasEmbeds && !hasAttachments) && !hasFlags)
|
||||||
Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content));
|
Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content));
|
||||||
|
|
||||||
var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List<API.Embed>() : null;
|
var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List<API.Embed>() : null;
|
||||||
@@ -261,20 +265,41 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = new API.InteractionResponse
|
if (!args.Attachments.IsSpecified)
|
||||||
{
|
{
|
||||||
Type = InteractionResponseType.UpdateMessage,
|
var response = new API.InteractionResponse
|
||||||
Data = new API.InteractionCallbackData
|
|
||||||
{
|
{
|
||||||
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
|
Data = new API.InteractionCallbackData
|
||||||
|
{
|
||||||
|
Content = args.Content,
|
||||||
|
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
|
||||||
|
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
|
||||||
|
Components = args.Components.IsSpecified
|
||||||
|
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
|
||||||
|
: Optional<API.ActionRowComponent[]>.Unspecified,
|
||||||
|
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var response = new API.Rest.UploadInteractionFileParams(args.Attachments.Value.ToArray())
|
||||||
|
{
|
||||||
|
Type = InteractionResponseType.UpdateMessage,
|
||||||
Content = args.Content,
|
Content = args.Content,
|
||||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
|
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional<API.AllowedMentions>.Unspecified,
|
||||||
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
|
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,
|
||||||
Components = args.Components.IsSpecified
|
MessageComponents = args.Components.IsSpecified
|
||||||
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
|
? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>()
|
||||||
: Optional<API.ActionRowComponent[]>.Unspecified,
|
: Optional<API.ActionRowComponent[]>.Unspecified,
|
||||||
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
|
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional<MessageFlags>.Unspecified : Optional<MessageFlags>.Unspecified
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
@@ -284,7 +309,6 @@ namespace Discord.WebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await InteractionHelper.SendInteractionResponseAsync(Discord, response, this, Channel, options).ConfigureAwait(false);
|
|
||||||
HasResponded = true;
|
HasResponded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user