Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
Update DiscordRestApiClient.cs (#357)
Browse files Browse the repository at this point in the history
Add missing check to Content value to prevent NRE on empty message. 
Also made `ModifyInteractionFollowupMessageAsync`'s check consistent with `CreateInteractionFollowupMessageAsync`
  • Loading branch information
exsersewo authored Dec 10, 2021
1 parent 10d40fc commit 025d16b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,8 +1353,7 @@ public async Task<Message> CreateInteractionFollowupMessageAsync(UploadWebhookFi
if ((!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0) && !args.Files.Any())
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content));


if (args.Content.IsSpecified && args.Content.Value.Length > DiscordConfig.MaxMessageSize)
if (args.Content.IsSpecified && args.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(args.Content));

options = RequestOptions.CreateOrClone(options);
Expand All @@ -1368,9 +1367,8 @@ public async Task<Message> ModifyInteractionFollowupMessageAsync(ModifyInteracti
Preconditions.NotNull(args, nameof(args));
Preconditions.NotEqual(id, 0, nameof(id));

if (args.Content.IsSpecified)
if (args.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(args.Content));
if (args.Content.IsSpecified && args.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(args.Content));

options = RequestOptions.CreateOrClone(options);

Expand Down

0 comments on commit 025d16b

Please sign in to comment.