Skip to content

Commit

Permalink
Fix null error when using a SelectMenuBuilder constructor (#2924)
Browse files Browse the repository at this point in the history
* Fix null error when using a `SelectMenuBuilder` constructor

* Update references to `Options` to support `null`
  • Loading branch information
Hampo authored May 11, 2024
1 parent 54d2fe5 commit 93cb71a
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal void AddComponent(IMessageComponent component, int row)
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;
}
}
Expand Down Expand Up @@ -1040,6 +1040,8 @@ public SelectMenuBuilder WithOptions(List<SelectMenuOptionBuilder> options)
/// </returns>
public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option)
{
Options ??= new();

if (Options.Count >= MaxOptionCount)
throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");

Expand Down

0 comments on commit 93cb71a

Please sign in to comment.