Unregistering Slash commands
See original GitHub issueI’ve followed your guide and a few others and it all works nicely. Problem is, I have deleted some of the commands (like /ping /server /user) that were just for learning purposes. Now I still have them registered on my server, and on another server the new commands that I created seem to be duplicated, probably because I registered them once as guild commands, then as client commands.
How do I clean up the registered commands?
sharing my deploy-commands.js `const fs = require(‘fs’); const { REST } = require(‘@discordjs/rest’); const { Routes } = require(‘discord-api-types/v9’); const { clientId, guildId, token } = require(‘./config.json’);
// 0 for guild, 1 for client. const mode = 1;
// Populate commands list const commands = []; const commandFiles = fs.readdirSync(‘./commands’).filter(file => file.endsWith(‘.js’));
for (const file of commandFiles) {
const command = require(./commands/${file}
);
commands.push(command.data.toJSON());
}
console.log(‘Registering commands:’); console.log(commands);
const rest = new REST({ version: ‘9’ }).setToken(token);
if (mode === 0) {
// update command list for guild (FreeSouls server). used for testing.
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log(‘Successfully registered application Guild commands.’))
.catch(console.error);
} else {
// Globally updates commands on all servers. Cached commands take up to 1h to be updated.
rest.put(Routes.applicationCommands(clientId), { body: commands })
.then(() => console.log(‘Successfully registered application commands.’))
.catch(console.error);
}`
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Assuming you have the ids for the commands and you can evaluate this: If you’re trying to delete a
guild
command:If you’re trying to delete a
global
command:If you’re using the
@discordjs/rest
module (as you have shown), you canPUT
(rest.put()
) an empty array to delete all commands or exclude the commands you want to delete from the array. In this case, just delete the files for the commands you don’t need or move them to a different folder (not incommands
) and register them.You should now only see a single set of commands.
I have to admit that at first I didn’t understand that Global and Guild commands were 2 separate sets and could coexist. The guide is a great help but a small note about this wouldn’t hurt :p