CabbageAdi / DSharpPlus.SlashCommands

An extension for DSharpPlus to make slash commands easier
https://discord.gg/2ZhXXVJYhU
MIT License
44 stars 11 forks source link

Using `[SlashCommandGroup]` appears to be non-functional #17

Closed VelvetToroyashi closed 3 years ago

VelvetToroyashi commented 3 years ago

Attempting to mark a class a group, and putting methods inside that class registers them as top-level commands instead of group commands.

    [SlashCommandGroup("test", "Testing!")]
    public class Test : SlashCommandModule
    {
        [SlashCommandGroup("testing", "aaaaa")]
        public class Test2 : SlashCommandModule
        {
            [SlashCommand("aaaa", "aaaa, but 1")]
            public Task A(InteractionContext ctx) => ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new() {Content = "A", IsEphemeral = true});

            [SlashCommand("bbbb", "aaaa, but 1")]
            public Task B(InteractionContext ctx) => ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new() {Content = "B", IsEphemeral = true});

            [SlashCommand("cccc", "aaaa, but 1")]
            public Task C(InteractionContext ctx) => ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new() {Content = "C", IsEphemeral = true});

        }
    }

Registers them properly But doing something like:

Registers them as top-level commands

This is all based on what's advised in the readme

CabbageAdi commented 3 years ago

This is a known issue/intended behaviour. You're supposed to create a group inside your main command class, marking the command class as a group does nothing. You should be doing

public class GroupedCommands : SlashCommandModule
{
    [SlashCommandGroup("test", "Testing!")]
    public class Test : SlashCommandModule
    {
        [SlashCommandGroup("testing", "aaaaa")]
        public class Test2 : SlashCommandModule
        {
            [SlashCommand("aaaa", "aaaa, but 1")]
            public Task A(InteractionContext ctx) => ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new() {Content = "A", IsEphemeral = true});

            [SlashCommand("bbbb", "aaaa, but 1")]
            public Task B(InteractionContext ctx) => ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new() {Content = "B", IsEphemeral = true});

            [SlashCommand("cccc", "aaaa, but 1")]
            public Task C(InteractionContext ctx) => ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new() {Content = "C", IsEphemeral = true});

        }
    }
}
VelvetToroyashi commented 3 years ago

Requiring a nested type for make a slash command group is a bit...cumbersome.

VelvetToroyashi commented 3 years ago

Especially when all you want is a group

CabbageAdi commented 3 years ago

This has been fixed in the latest version