From 8dce6a6e1f815af3c94bdea43d32f54e439400ec Mon Sep 17 00:00:00 2001 From: quin lynch Date: Thu, 5 Aug 2021 15:51:56 -0300 Subject: [PATCH] Add single embed message property back for backwards compatibility --- .../Entities/Messages/MessageProperties.cs | 8 +++++ .../Entities/Messages/MessageHelper.cs | 29 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs b/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs index f4971b69e..19cfacebe 100644 --- a/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs +++ b/src/Discord.Net.Core/Entities/Messages/MessageProperties.cs @@ -18,6 +18,14 @@ namespace Discord /// public Optional Content { get; set; } + /// + /// Gets or sets a single embed for this message. + /// + /// + /// This property will be added to the array, in the future please use the array rather then this property. + /// + public Optional Embed { get; set; } + /// /// Gets or sets the embeds of the message. /// diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 5812a7316..83ad2777e 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -61,10 +61,22 @@ namespace Discord.Rest } } + var embeds = new List(); + + if (args.Embed.IsSpecified) + { + embeds.Add(args.Embed.Value.ToModel()); + } + + if (args.Embeds.IsSpecified) + { + embeds.AddRange(args.Embeds.Value.Select(x => x.ToModel())); + } + var apiArgs = new ModifyMessageParams { Content = args.Content, - Embeds = args.Embeds.IsSpecified ? args.Embeds.Value.Select(x => x.ToModel()).ToArray() : Optional.Unspecified, + Embeds = embeds.ToArray(), Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified, Flags = args.Flags, AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Unspecified, @@ -105,12 +117,25 @@ namespace Discord.Rest } } + var embeds = new List(); + + if (args.Embed.IsSpecified) + { + embeds.Add(args.Embed.Value.ToModel()); + } + + if (args.Embeds.IsSpecified) + { + embeds.AddRange(args.Embeds.Value.Select(x => x.ToModel())); + } + var apiArgs = new API.Rest.ModifyMessageParams { Content = args.Content, - Embeds = args.Embeds.IsSpecified ? args.Embeds.Value.Select(x => x.ToModel()).ToArray() : Optional.Create(), + Embeds = embeds.ToArray(), Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create(), AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create(), + Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified, }; return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false); }