Skip to content

Commit 8668092

Browse files
authored
[Fix] Correct IUserMessage.ModifyAsync precondition expression
1 parent 80fbbc2 commit 8668092

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ public static Task<Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordC
3838
var embed = args.Embed;
3939
var embeds = args.Embeds;
4040

41-
bool hasText = args.Content.IsSpecified && string.IsNullOrEmpty(args.Content.Value);
42-
bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0;
43-
bool hasComponents = args.Components.IsSpecified && args.Components.Value != null;
41+
bool hasText = args.Content.IsSpecified && !string.IsNullOrEmpty(args.Content.Value);
42+
bool hasEmbeds = embed is { IsSpecified: true, Value: not null }
43+
|| embeds is { IsSpecified: true, Value.Length: > 0 };
44+
bool hasComponents = args.Components is { IsSpecified: true, Value: not null };
4445
bool hasAttachments = args.Attachments.IsSpecified;
4546
bool hasFlags = args.Flags.IsSpecified;
4647

@@ -50,7 +51,7 @@ public static Task<Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordC
5051

5152
if (args.AllowedMentions.IsSpecified)
5253
{
53-
AllowedMentions allowedMentions = args.AllowedMentions.Value;
54+
var allowedMentions = args.AllowedMentions.Value;
5455
Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
5556
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
5657

@@ -73,12 +74,12 @@ public static Task<Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordC
7374

7475
var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List<API.Embed>() : null;
7576

76-
if (embed.IsSpecified && embed.Value != null)
77+
if (embed is { IsSpecified: true, Value: not null })
7778
{
7879
apiEmbeds.Add(embed.Value.ToModel());
7980
}
8081

81-
if (embeds.IsSpecified && embeds.Value != null)
82+
if (embeds is { IsSpecified: true, Value: not null })
8283
{
8384
apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel()));
8485
}
@@ -87,7 +88,7 @@ public static Task<Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordC
8788

8889
if (!args.Attachments.IsSpecified)
8990
{
90-
var apiArgs = new API.Rest.ModifyMessageParams
91+
var apiArgs = new ModifyMessageParams
9192
{
9293
Content = args.Content,
9394
Embeds = apiEmbeds?.ToArray() ?? Optional<API.Embed[]>.Unspecified,

0 commit comments

Comments
 (0)