#delete all commands

11 messages · Page 1 of 1 (latest)

left ibex
#
    async ResetCommands(guildId) {
        var guild = this.Client.guilds.cache.get(guildId);
        try {
            var commands = await guild.commands.fetch();

            if (commands.size == 0) return;

            for (const command of commands.values()) {
                await guild.commands.delete(command.id);
                console.log(`Deleted command in guild ${guild.name}: ${command.name}`);
            }
        } catch (err) {
            console.log(err);
        }

        // this.Rest.put(Routes.applicationCommands(this.Client.user.id), { body: [] });
    }

I'm trying to get a command, but the commands keep returning 0.
Maybe I missed something?

safe scrollBOT
#
  • 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 OP
winged falcon
#

What are you trying to achieve with your code

left ibex
atomic swiftBOT
#

If you have duplicate commands on your server, you registered both global and guild commands.

You can remove the duplicates by resetting either the global or guild commands

  • Resetting global commands: rest.put(Routes.applicationCommands(clientId), { body: [] })
  • Resetting guild commands: rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
winged falcon
#

Just use the second method, you don't need to fetch or do them one by one

#

You shouldn't be doing this every time your bot starts, either

left ibex
#

I already try that one but nothing happen

#

I will try again now

#

it's work with Global Command

#

oh