From 93cb71af57ba9cd7ab204acd5a93e61850fabfd2 Mon Sep 17 00:00:00 2001 From: Proddy Date: Sat, 11 May 2024 21:23:51 +0100 Subject: [PATCH] Fix null error when using a `SelectMenuBuilder` constructor (#2924) * Fix null error when using a `SelectMenuBuilder` constructor * Update references to `Options` to support `null` --- .../Interactions/MessageComponents/ComponentBuilder.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs index 1af47415..e3c1623c 100644 --- a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs @@ -77,7 +77,7 @@ namespace Discord AddComponent(cmp, row); break; case SelectMenuComponent menu: - WithSelectMenu(menu.CustomId, menu.Options.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.IsDefault)).ToList(), menu.Placeholder, menu.MinValues, menu.MaxValues, menu.IsDisabled, row); + WithSelectMenu(menu.CustomId, menu.Options?.Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.IsDefault)).ToList(), menu.Placeholder, menu.MinValues, menu.MaxValues, menu.IsDisabled, row); break; } } @@ -1040,6 +1040,8 @@ namespace Discord /// public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option) { + Options ??= new(); + if (Options.Count >= MaxOptionCount) throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");