From b1c2fcb61019d9ad9685c8a7ab7b81283ad4707c Mon Sep 17 00:00:00 2001 From: d4n Date: Fri, 16 May 2025 00:53:31 -0500 Subject: [PATCH] Fix error when only sending components in response to interactions (#3129) --- src/Discord.Net.Rest/DiscordRestApiClient.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 97a3be95..55acb270 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -1472,10 +1472,15 @@ namespace Discord.API 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()) - Preconditions.NotNullOrEmpty(response.Content, nameof(response.Content)); + if ((!response.Embeds.IsSpecified || response.Embeds.Value == null || response.Embeds.Value.Length == 0) + && (!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)); options = RequestOptions.CreateOrClone(options);