Creating slash command
To create a slash command, you need to export by default an object containing the following information:
name (string): The name of the command. For example, if the name is set to "test," the command will be /test.
description (string): A description of what the command does.
type (ApplicationCommandType): The type of command. You can find the command type in the discord.js documentation by clicking here.
run (function): The function that will be called when the command is executed. This function will receive
client
andinteraction
as parameters.
Exemplo de codigo:
This function responds to the /test command with a "Hello World!"
For this command to actually work, we need to specify the location of the folder containing the commands during the setup, like this:
This way, all commands should be loaded correctly, as long as all command files are inside the "commands" folder located in the root directory of the bot. It doesn't necessarily have to be the "commands" folder; you can define the folder using the .set
method of the easeClient.
Now we need to learn more about components, which can be sent as responses to slash commands or other interactions.
Last updated