Fix NullReferenceException caused by Options being undefined. (#2549)
This commit is contained in:
committed by
GitHub
parent
4aded83ab6
commit
02d3ce6e01
@@ -664,7 +664,9 @@ namespace Discord
|
|||||||
if (options == null)
|
if (options == null)
|
||||||
throw new ArgumentNullException(nameof(options), "Options cannot be null!");
|
throw new ArgumentNullException(nameof(options), "Options cannot be null!");
|
||||||
|
|
||||||
if ((Options?.Count ?? 0) + options.Length > SlashCommandBuilder.MaxOptionsCount)
|
Options ??= new List<SlashCommandOptionBuilder>();
|
||||||
|
|
||||||
|
if (Options.Count + options.Length > SlashCommandBuilder.MaxOptionsCount)
|
||||||
throw new ArgumentOutOfRangeException(nameof(options), $"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!");
|
throw new ArgumentOutOfRangeException(nameof(options), $"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!");
|
||||||
|
|
||||||
foreach (var option in options)
|
foreach (var option in options)
|
||||||
|
|||||||
@@ -34,4 +34,22 @@ public class CommandBuilderTests
|
|||||||
.AddChoice("choice2", "2"));
|
.AddChoice("choice2", "2"));
|
||||||
command.Build();
|
command.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void BuildSubSlashCommand()
|
||||||
|
{
|
||||||
|
var command = new SlashCommandBuilder()
|
||||||
|
.WithName("command").WithDescription("Command desc.")
|
||||||
|
.AddOptions(new SlashCommandOptionBuilder()
|
||||||
|
.WithType(ApplicationCommandOptionType.SubCommand)
|
||||||
|
.WithName("subcommand").WithDescription("Subcommand desc.")
|
||||||
|
.AddOptions(
|
||||||
|
new SlashCommandOptionBuilder()
|
||||||
|
.WithType(ApplicationCommandOptionType.String)
|
||||||
|
.WithName("name1").WithDescription("desc1"),
|
||||||
|
new SlashCommandOptionBuilder()
|
||||||
|
.WithType(ApplicationCommandOptionType.String)
|
||||||
|
.WithName("name2").WithDescription("desc2")));
|
||||||
|
command.Build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user