#How to Register commands

1 messages · Page 1 of 1 (latest)

thorn tangle
#

I am confused how to register new commands~
Read through the documentation and it says I got to register the to a guild or global.
But they not register in my guild and also the bot doesn't have the 'supported slash command' badge?
Did I forget something or did something wrong Think help is appreciated

public class Program : InteractionModuleBase { 

    private DiscordSocketClient _client;

    public static Task Main(string[] args) => new Program().MainAsync();

    public async Task MainAsync() {
        _client = new DiscordSocketClient();
        _client.Log += Log;
        _client.Ready += OnReady;

        var token = "mysecret";

        await _client.LoginAsync(TokenType.Bot, token);
        await _client.StartAsync();

        // Block this task until the program is closed.
        await Task.Delay(-1);
    }

    private async Task OnReady() {
        await Log(new LogMessage(LogSeverity.Info, "Main", "Ready To Be Used"));

        var _interactionService = new InteractionService(_client.Rest);
#if DEBUG
        await _interactionService.RegisterCommandsToGuildAsync(mytestingguildid);
#else
        await _interactionService.RegisterCommandsGloballyAsync();
#endif
        return;
    }

    private Task Log(LogMessage msg) {
        Console.WriteLine(msg.ToString());
        return Task.CompletedTask;
    }

    [SlashCommand("echo", "Echo an input")]
    public async Task Echo(string input) {
        await RespondAsync(input);
    }

}```
half tangle
#

You need to add the SlashCommand within its own class that inherits from InteractionModuleBase<SocketInteractionContext>.

#
GitHub

An unofficial .Net wrapper for the Discord API (https://discord.com/) - Discord.Net/samples/InteractionFramework at dev · discord-net/Discord.Net