Dsharpplus not responding to commands

1k Views Asked by At

Ok so I am trying to experiment with c# discord bots so I found an old repository with a basic bot template however after running the bot It seems the commands are either not being registered properly or are not being called correctly.

Main Bot file

_discordClient = new DiscordClient(clientConfig);
/* TELL IT TO USE COMMANDSNEXT */
_commandsNext = _discordClient.UseCommandsNext(commandConfig);

/* REGISTER COMMANDS */
_commandsNext.RegisterCommands<Commands.Commands>();
Console.WriteLine("Comands Loaded");```

Command file

namespace Bot_Framework.Commands
{
    public class Commands
    {
        [Command("test"), Description("A simple test command")]
        public async Task test(CommandContext ctx)
        {
            await ctx.Message.DeleteAsync();
            await ctx.RespondAsync("Hello World!");
        }
    }
}

Im using an older version of dsharp

Packages

  <package id="DSharpPlus" version="3.2.3" targetFramework="net472" />
  <package id="DSharpPlus.CommandsNext" version="3.2.3" targetFramework="net472" />

Not sure what im doing wrong or if its just something simple. If any other information is needed ask and I can send it.

1

There are 1 best solutions below

0
On

I know this is an old question but I figured I'd respond to it in case if anyone ever searches this here. There are two things we need to change, and we'll take them on one at a time.

The most obvious cause of the issue to anyone who uses Discord is that the message is being deleted before replying, you cannot reply to a deleted message. Instead of the way its set up above you'd want to change it to this:

namespace Bot_Framework.Commands
{
    public class Commands
    {
        [Command("test"), Description("A simple test command")]
        public async Task test(CommandContext ctx)
        {
            await ctx.RespondAsync("Hello World!");
            await ctx.Message.DeleteAsync(); // Delete after!
        }
    }
}

The second issue I see is that they are registering commands from Commands.Commands which is not calling the proper base class. It should be formatted as follows:

namespace Bot_Framework.Commands
{
    public class Commands : BaseCommandModule //Your class needs to know what it is!
    {
        [Command("test"), Description("A simple test command")]
        public async Task test(CommandContext ctx)
        {
            await ctx.RespondAsync("Hello World!");
            await ctx.Message.DeleteAsync();
        }
    }
}