Creating Command Modules
The easiest way to create commands is by adding module classes to your project, i.e. classes that inherit DiscordModuleBase
or DiscordGuildModuleBase
.
See more: xref
I called the class I made BotModule
. The name can be anything and you can have as many modules as you want.
Now, paste the following code in:
using Disqord.Bot;
using Qmmands;
namespace MyBot
{
// DiscordModuleBase is required to mark the class as a command module.
public class BotModule : DiscordModuleBase
{
// The command attribute marks the method as a command, with 'ping' as the alias.
[Command("ping")]
public DiscordCommandResult Ping()
{
// Means the command should respond with the given string.
return Response("Pong!");
}
}
}
This adds a basic ping-pong command. Let's try it out! Boot up your bot and type ?ping
, !ping
or @YourBot ping
in a channel.