Slash
How to create discord slash commands
Creating slash commands
First of all, import the createCommand
function from base and ApplicationCommandType
from discord.js
See conventions to create your commands
How to create slash command
To create a slash command, you need to set name, description and type.
Slash command names cannot be empty, cannot contain special characters, capital letters or spaces
Set slash command options
You can set options, subcommands and groups too
Global
The global
option in commands is useful when you want the command to be registered to the application rather than the guild. It is only needed when guild IDs are set in the setupCreators function.
The code below causes commands to be registered only to the valid guilds listed in the array:
Now look at this code where some commands are created:
The settings
and manage
commands will be registered in the guilds defined in the setupCreators
function, but the information
command will be registered globally in the application, thus being available in any guild.