From 37d9bb3ddd6c9490e217f32f77d4ed420d4fd299 Mon Sep 17 00:00:00 2001 From: CottageDwellingCat <80918250+CottageDwellingCat@users.noreply.github.com> Date: Thu, 18 Nov 2021 02:18:37 -0600 Subject: [PATCH] Automatically fix ordering of optional command options (#276) * auto fix optional command option order * clean up indentation --- .../Interactions/SlashCommands/SlashCommandBuilder.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs index e6696bde4..25c1f1dd9 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs @@ -100,7 +100,7 @@ namespace Discord { var options = new List(); - Options.ForEach(x => options.Add(x.Build())); + Options.OrderByDescending(x => x.Required ?? false).ToList().ForEach(x => options.Add(x.Build())); props.Options = options; } @@ -378,7 +378,9 @@ namespace Discord Default = Default, Required = Required, Type = Type, - Options = Options?.Count > 0 ? Options.Select(x => x.Build()).ToList() : new List(), + Options = Options?.Count > 0 + ? Options.OrderByDescending(x => x.Required ?? false).Select(x => x.Build()).ToList() + : new List(), Choices = Choices, Autocomplete = Autocomplete, ChannelTypes = ChannelTypes,