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:
@@ -77,7 +77,7 @@ namespace Discord
|
|||||||
AddComponent(cmp, row);
|
AddComponent(cmp, row);
|
||||||
break;
|
break;
|
||||||
case SelectMenuComponent menu:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1040,6 +1040,8 @@ namespace Discord
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option)
|
public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option)
|
||||||
{
|
{
|
||||||
|
Options ??= new();
|
||||||
|
|
||||||
if (Options.Count >= MaxOptionCount)
|
if (Options.Count >= MaxOptionCount)
|
||||||
throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");
|
throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user