Delete slash command if it is "forgotten"
I have a problem with my guilds slash commands where If I delete a command in my code, it stays in the guild. Now I'm trying to code something to delete the slash command if it doesn't "exist" anymore in the code, but I'm getting an error. Here's my output:
The code to delete the slash command is the following:
Can't I use the command interaction ID to delete it?
❯ npm start
> discord-dev-env@1.3.1 start
> node scripts/start.js && npm run build && cd dist && node src/index.js
> discord-dev-env@1.3.1 build
> rimraf dist/* && tsc && tsc-alias && tscp
Non-typescript files copied
discord-dev-env
✓ Created logs folder at: /Users/marlon/Javascript/discord-dev-env/dist/logs
✓ Logged in as xxx#0000!
ℹ Initalizing Events...
✓ Events have been loaded! [interactionCreate.js]
ℹ Started deploying slash commands...
✓ Cleared global commands cache!
ℹ Scanning commands in "/Users/marlon/Javascript/discord-dev-env/dist/src/commands"
✓ (/) Reloaded guild-specific commands for 0 guilds.
✓ (/) Reloaded 3 global commands
✓ All slash commands have been deployed. The bot is ready to run!
✖ An error occured while deleting left-over command:
DiscordAPIError[10063]: Unknown application command❯ npm start
> discord-dev-env@1.3.1 start
> node scripts/start.js && npm run build && cd dist && node src/index.js
> discord-dev-env@1.3.1 build
> rimraf dist/* && tsc && tsc-alias && tscp
Non-typescript files copied
discord-dev-env
✓ Created logs folder at: /Users/marlon/Javascript/discord-dev-env/dist/logs
✓ Logged in as xxx#0000!
ℹ Initalizing Events...
✓ Events have been loaded! [interactionCreate.js]
ℹ Started deploying slash commands...
✓ Cleared global commands cache!
ℹ Scanning commands in "/Users/marlon/Javascript/discord-dev-env/dist/src/commands"
✓ (/) Reloaded guild-specific commands for 0 guilds.
✓ (/) Reloaded 3 global commands
✓ All slash commands have been deployed. The bot is ready to run!
✖ An error occured while deleting left-over command:
DiscordAPIError[10063]: Unknown application commandThe code to delete the slash command is the following:
const command = interaction.client.commands.get(interaction.commandName)
if (!command) {
const rest = new REST().setToken(process.env.token)
try {
rest.delete(Routes.applicationGuildCommand(process.env.clientId,interaction.guild.id,interaction.id))
.then(()=> logging(`Deleted leftover command ${interaction.commandName} in guild "${interaction.guild.id}`,"minimal"))
.catch(err => logging(`An error occured while deleting left-over command:\n${err}`,"error"))
} catch (error) {
logging("An error occured while deleting left-over command:\n" + error,"error")
}
interaction.reply({content: "Command is outdated. It cannot be used anymore."})
return
}const command = interaction.client.commands.get(interaction.commandName)
if (!command) {
const rest = new REST().setToken(process.env.token)
try {
rest.delete(Routes.applicationGuildCommand(process.env.clientId,interaction.guild.id,interaction.id))
.then(()=> logging(`Deleted leftover command ${interaction.commandName} in guild "${interaction.guild.id}`,"minimal"))
.catch(err => logging(`An error occured while deleting left-over command:\n${err}`,"error"))
} catch (error) {
logging("An error occured while deleting left-over command:\n" + error,"error")
}
interaction.reply({content: "Command is outdated. It cannot be used anymore."})
return
}Can't I use the command interaction ID to delete it?