#Delete slash command if it is "forgotten"

49 messages · Page 1 of 1 (latest)

broken prairie
#

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:


> [email protected] start
> node scripts/start.js && npm run build && cd dist && node src/index.js


> [email protected] 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```

The code to delete the slash command is the following:
```ts
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?
deep canyonBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by staff
broken prairie
lean obsidian
#

I just use set as opposed to create when deploying commands to avoid the need for deleting commands

#

Well, put instead of post if using rest

lean obsidian
#

Put instead of post

broken prairie
#

Oh, what's the difference?

#

It's temporary maybe?

lean obsidian
#

put sets alls commands

broken prairie
#

Oh yeah

lean obsidian
#

Whatever array of commands you provide will become the entire set of commands (new ones are created, removed ones are deleted, others are updated if needed)

#

The creates are still counted against the creation rate limit, but the rest isn’t

#

Heh, rest

broken prairie
#

I already use put lol

#

Wait maybe i'm getting old commands

lean obsidian
#

Try running the old command

#

It shouldn’t go to the bot

broken prairie
#

Well it says the message

#

wait

lean obsidian
#

Yea

broken prairie
#

I'm maybe guessing that i'm getting old commands before pushing

lean obsidian
#

Is that from ur bot?

broken prairie
#

Yes

#

(dont mind the name it's not the actual bot lol)

lean obsidian
#

Are you sure the command got removed from the array?

broken prairie
#

I'll try logging it

#

Oh yeah also

#

If I remove every guild commands then the guild deploy part will not run

#

and therefor not overwrite the old guild commands

#

that's why

#

Yeah now it works

#

When I add a guild command

lean obsidian
#

You don’t manually run the deploy script while testing?

broken prairie
lean obsidian
#

Usually, application command deployment is its own script

broken prairie
#

Oh yes it is its own script

#

What I mean is that If I delete all guild commands, the part where it deploys guild commands will not run, so it will not overwrite the old commands

#

That's why I wanted to delete the command if it was old

lean obsidian
#

I’m not rly sure what your mean

#

My deploy script just reads the commands directory to see available commands, then sets the commands to match that

broken prairie
#

Yes but I'm talking about guild-specifc commands

#

My script is halfed into global, and guild commands.
The global deploy always run.
The guilds one only runs if one command in the code is guild-specific

#

I could send it If you want

lean obsidian
#

I would just have it always deploy

#

Even if there are no commands

broken prairie
#

I have to go but I'll try to explain it better later