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
    }
]);

Learn more on how to detect when Application Commands are executed.

Last updated