Fix error when only sending components in response to interactions (#3129)

This commit is contained in:
d4n
2025-05-16 00:53:31 -05:00
committed by GitHub
parent 9f9b093add
commit b1c2fcb610

View File

@@ -1472,10 +1472,15 @@ namespace Discord.API
public Task CreateInteractionResponseAsync(UploadInteractionFileParams response, ulong interactionId, string interactionToken, RequestOptions options = null) public Task CreateInteractionResponseAsync(UploadInteractionFileParams response, ulong interactionId, string interactionToken, RequestOptions options = null)
{ {
if ((!response.Embeds.IsSpecified || response.Embeds.Value == null || response.Embeds.Value.Length == 0) && !response.Files.Any()) if ((!response.Embeds.IsSpecified || response.Embeds.Value == null || response.Embeds.Value.Length == 0)
Preconditions.NotNullOrEmpty(response.Content, nameof(response.Content)); && (!response.Content.IsSpecified || response.Content.Value is null || string.IsNullOrWhiteSpace(response.Content.Value))
&& (!response.MessageComponents.IsSpecified || response.MessageComponents.Value is null || response.MessageComponents.Value.Length == 0)
&& (response.Files is null || response.Files.Length == 0))
{
throw new ArgumentException("At least one of 'Content', 'Embeds', 'Files' or 'MessageComponents' must be specified.", nameof(response));
}
if (response.Content.IsSpecified && response.Content.Value.Length > DiscordConfig.MaxMessageSize) if (response.Content.IsSpecified && response.Content.Value?.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(response.Content)); throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(response.Content));
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);