- In your project folder, make a new folder called
commands/
. - In the
commands/
folder, create ahello.js
file with the following contents:
module.exports = {
name: 'hello',
aliases: ['greet'],
description: 'Greets the command user.',
execute ({ message, args, server }) {
message.channel.send(`Hello, ${message.author}!`)
}
}
Let's break down each property of the command configuration object:
name: 'hello'
The name
property is the name of the command, which must be unique. You can overwrite default commands by simply reusing the command name in your own local command file. The bot will listen for this string in order to execute the command.
aliases: ['greet']
The aliases
property is optional and allows you to designate any strings that will serve as an alias for the command name
. In this case, the user can also fire this command with the greet
alias. Currently, aliases do not have to be unique and using an alias will fire the first matching record in the Esdi
instance. If an alias is the same as another command's name
, the command using it as a name
will take priority.
description: 'Greets the command user.'
The description
property is also optional and allows you to describe the command. This is used by the help
command.
execute ({ message, args, server }) {
message.reply(', hello!')
}
The execute
function is the substance of your command. This function fires when the command is invoked. You can use the properties (message
, args
, and server
) that are passed in an object to this function. message
refers to the discord.js Message object, args
refers to the array of space-separated argument strings following the command, and server
refers to the Esdi
instance. You can use this
to refer to the Command
object representing this loaded command.
To learn more about the command configuration options, check out the Command
documentation.
- Restart your Esdi server.
- In your server, fire the command. Use the bot prefix (e.g.,
esdi!
) together with thehello
command orgreeting
alias to see your new custom command in action:
- Continue developing your command, or make a brand new one! You can use anything from the discord.js Message object (which has access to everything about your discord.js Client) and the
Esdi
instance. You can also implement functionality from own your applications or third-party APIs. You don't even have to restart your server while building. Use thereload
command (e.g.,esdi!reload <command>
) to reload your command file on the fly once it's initially loaded. Your creativity is the limit!
Next, let's enable the github-redeploy
global Hook for our Esdi server.