How to unregister/delete a slash command in discord.js?

Member

by larissa , in category: Javascript , 8 days ago

How to unregister/delete a slash command in discord.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 7 days ago

@larissa 

To unregister or delete a slash command in discord.js, you can use the following method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');

const commands = [
    // array of commands to delete
];

const rest = new REST({ version: '9' }).setToken('YOUR_BOT_TOKEN');

(async () => {
    try {
        console.log('Deleting commands...');

        await rest.put(
            Routes.applicationCommands(CLIENT_ID),
            { body: [] }, // empty array to delete all commands
        );

        console.log('Successfully deleted commands.');
    } catch (error) {
        console.error(error);
    }
})();


Replace YOUR_BOT_TOKEN with your bot token and CLIENT_ID with your bot's client ID. Update the commands array with the commands you want to delete.


After running this script, all the commands specified in the commands array will be unregistered/deleted from your Discord bot.