Your First Command
#
IntroductionThe smallest Discapp command looks like this:
This is the !ping
command, the only thing it does is to send 'pong' whenever the user sents 'ping'.
It's useful to verify if your bot is working and comes by default in a Discapp project.
#
Concepts#
LocationAll the commands must be in path/to/your/app/Commands
directory if you have setup your project with create-discapp
.
This is where Discapp will look for commands, commands in this location are automatically loaded.
#
CodeEvery Discapp command has a "code". Think of a command's code as a name, in fact the code is basically a command name.
Every command must have an unique code, so it can be distinguished from other commands.
In Discapp, the code of a command can be either implicitly defined, for example:
In this case, the code of the command is ping
as defined in @Command('ping')
.
A command code can also be implicit, as in the code in introduction. In this case the code is also ping
, because if you name your class using the Discapp convention, Discapp will automatically infer the code:
PingCommand
->ping
HelpCommand
->help
ShowMeCommand
->show-me
Discapp basically removes the 'Command' suffix and convert the remaining to kebab-case.
execute
method#
The Every command must have a public execute
method, this is the method that will get invoked when the user sends a message with the code.
Returns of the execute
method will be automatically send as replies by Discapp.
The execute
method can also be async
.