Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BrammyS committed Feb 22, 2022
2 parents 7947723 + 7ba1bd8 commit 75157f2
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task<InternalInteractionResponse> HandleSlashCommandAsync(IDiscordI
IEnumerable<IDiscordInteractionOption>? options = null;

// Get the command name and the options.
if (interaction.Data.Options is null)
if (interaction.Data.Options is null || !ContainsSubCommand(interaction))
{
options = interaction.Data.Options;
context.SlashCommandName = new[] { interaction.Data.Name };
Expand Down Expand Up @@ -211,5 +211,14 @@ async Task<Result<IDiscordInteractionResponse>> Handler()

throw new SlashCommandResultException($"Command request {interaction.Id} returned unsuccessfully, {result.ErrorResult?.ErrorMessage}");
}

private static bool ContainsSubCommand(IDiscordInteraction interaction)
{
if (interaction.Data?.Options is null)
return false;

return interaction.Data.Options.Select(x => x.Type).Contains(DiscordApplicationCommandOptionType.SubCommand) ||
interaction.Data.Options.Select(x => x.Type).Contains(DiscordApplicationCommandOptionType.SubCommandGroup);
}
}
}

0 comments on commit 75157f2

Please sign in to comment.