question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unregistering Slash commands

See original GitHub issue

I’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); }` image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
WiseDevHelpercommented, Sep 24, 2021

Assuming you have the ids for the commands and you can evaluate this: If you’re trying to delete a guild command:

const command = await client.guilds.cache.get('123456789012345678')?.commands.fetch('876543210987654321');
await command.delete();

If you’re trying to delete a global command:

const command = client.application?.commands.fetch('123456789012345678');
await command.delete();

If you’re using the @discordjs/rest module (as you have shown), you can PUT (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 in commands) and register them.

You should now only see a single set of commands.

0reactions
Empi3commented, Oct 5, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to unregister/delete a slash command in Discord.js
To delete all global commands, use Client.application.commands.set() and pass an empty array client.application.commands.set([]).
Read more >
Deleting commands - discord.js Guide
To delete a specific command, you will need its id. Head to Server Settings -> Integrations -> Bots and Apps and choose your...
Read more >
How to unregister/delete a slash command in Discord.js ...
Coding example for the question How to unregister/delete a slash command in ... To delete all global commands, use Client.application.commands.set() and ...
Read more >
Add option to remove slash commands from a guild #2643
Slash commands can currently only be removed from a guild by removing the whole application, which also removes any related bot account and ......
Read more >
Deleted slash command wont go away from slash command list.
So i deleted a slash command from my code for several weeks ago and it still show up under `/`, is there anyway...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found