Fix null error when using a SelectMenuBuilder constructor (#2924)

* Fix null error when using a `SelectMenuBuilder` constructor

* Update references to `Options` to support `null`
This commit is contained in:
Proddy
2024-05-11 21:23:51 +01:00
committed by GitHub
parent 54d2fe5773
commit 93cb71af57

View File

@@ -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
/// </returns>
public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option)
{
Options ??= new();
if (Options.Count >= MaxOptionCount)
throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");