Registering
Learn how to register your application commands properly
First, we need to take a look at different types of application commands:
Global: can be used globally, on every guilds
Guild: can only be used in a specific guild
User: can only be used by a specific user
These are specific scopes that an application command can be applied to.
Global commands
To register a global command you'll need to use the following Client method: registerGlobalApplicationCommand
and pass your Application Command inside it.
Here's an example:
client.registerGlobalApplicationCommand({
name: "reminder",
type: ApplicationCommandType.CHAT_INPUT,
options: [
{
type: ApplicationCommandOptionType.INTEGER,
name: "minutes",
required: true
},
{
type: ApplicationCommandOptionType.STRING,
name: "message",
required: false
},
]
});
To register multiple global commands, you can use the bulkRegisterGlobalApplicationCommand
method.
Guild commands
It is pretty much the same as Global commands but you have to pass the Guild ID inside the registerGuildApplicationCommand
method.
client.registerGuildApplicationCommand(guildID, applicationCommand);
to register more than one guild command, you can use the alternative method: bulkRegisterGlobalApplicationCommand
, though you will have to specify the guild ID inside each object instead:
client.bulkRegisterGuildApplicationCommand([
{
name: "reminder",
type: ApplicationCommandType.CHAT_INPUT,
guildID: "INSERT GUILD ID",
options: [
{
type: ApplicationCommandOptionType.INTEGER,
name: "minutes",
required: true
},
{
type: ApplicationCommandOptionType.STRING,
name: "message",
required: false
},
],
// ..and more Application Commands
}
]);
User commands
It is pretty much the same as registering guild command(s), use the Client methdo called registerGuildApplicationCommand
:
client.registerUserApplicationCommand(userID, applicationCommand);
and for bulk registering use bulkRegisterUserApplicationCommand
and specify the User ID for each command:
client.bulkRegisterUserApplicationCommand([
{
name: "reminder",
type: ApplicationCommandType.CHAT_INPUT,
userID: "INSERT USER ID",
options: [
{
type: ApplicationCommandOptionType.INTEGER,
name: "minutes",
required: true
},
{
type: ApplicationCommandOptionType.STRING,
name: "message",
required: false
},
],
// ..and more Application Commands
}
]);
Command Option Types
There are a wide range of supported option types, filtering commands accordingly and notifying the user when some are wrong or haven't specified, if set as required.
STRING = 0, // Option has to be a string, either a word or "a sentence"
INTEGER = 1, // Integer type, no floating point allowed.
FLOAT = 2, // Float type, no integer allowed.
NUMBER = 3, // Floats & Integers are allowed.
SIGNED_32_INTEGER = 4, // Integer: -2147483648 to 2147483647
USER = 5, // User mention allowed
ROLE = 6 // Role mention allowed
CHANNEL = 7, // Channel mention allowed
// Image, or any embedded attchment that is found within the message content
EMBEDDED_ATTACHMENT = 8,
BOOLEAN = 9, // true or false (1 and 0 allowed)
EMOTE = 10, // Emote allowed
Learn more on how to detect when Application Commands are executed.
Last updated
Was this helpful?