Skip to content

Commit

Permalink
Prevents NREs when sending/modifying messages (discord-net#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quahu authored and FiniteReality committed May 5, 2018
1 parent 63bfbf5 commit 9604957
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public async Task<Message> CreateMessageAsync(ulong channelId, CreateMessagePara
if (!args.Embed.IsSpecified || args.Embed.Value == null)
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content));

if (args.Content.Length > DiscordConfig.MaxMessageSize)
if (args.Content?.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content));
options = RequestOptions.CreateOrClone(options);

Expand All @@ -487,7 +487,7 @@ public async Task<Message> CreateWebhookMessageAsync(ulong webhookId, CreateWebh
if (!args.Embeds.IsSpecified || args.Embeds.Value == null || args.Embeds.Value.Length == 0)
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content));

if (args.Content.Length > DiscordConfig.MaxMessageSize)
if (args.Content?.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content));
options = RequestOptions.CreateOrClone(options);

Expand Down Expand Up @@ -568,7 +568,7 @@ public async Task<Message> ModifyMessageAsync(ulong channelId, ulong messageId,
{
if (!args.Embed.IsSpecified)
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content));
if (args.Content.Value.Length > DiscordConfig.MaxMessageSize)
if (args.Content.Value?.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content));
}
options = RequestOptions.CreateOrClone(options);
Expand Down

0 comments on commit 9604957

Please sign in to comment.