#Slash Command Setup

1 messages · Page 1 of 1 (latest)

copper sinew
#

Hoping someone can help, It's been a few years since I used my cSharp hat. I'm attempting to setup a SlashBot in .Net Core 6. However, I'm attempting to break out the commands into their own namespace with 1 file per command for ease of management / function locating. I forget how to do this where it doesn't yell at me. Anyone have any help ?

        private async Task SlashCommandHandler(SocketSlashCommand command)
        {
            switch (command.Data.Name)
            {
                case "config":
                    await DiscordBotConfig(command);
                    break;
            }
        }```
is in my Primary Worker Function in namespace ``Utilities.Discord`` namespace, then I have the namespace ``Utilities.Discord.SlashCommands`` that I want to have contain the slash commands.
```csharp
using Discord.Commands;

namespace RPGUtilities.Discord.SlashCommands
{
    public class DiscordBotConfig
    {
        public async Task HandleAsync(SocketSlashCommand command)
        {
            await command.RespondAsync($"Attempting to just get this command working.");
        }   
    }
}
humble grove
#

So you can use it like this

#

It looks the same as One commands per namespace / class, but it's actually a single partial class splited into different files (when compiled, it's just one big class), i find it way more clear that way, for easy finding as you said.

#

Dont forget the disable checkNamespace (the // at the top), and use the same namespace as from where you defines "first" your partial class. Hope this helps