Home > Net >  Discord.js v13: Slash commands duped
Discord.js v13: Slash commands duped

Time:11-30

That seems like some bug or I don't know, but I'm sure this is fixable. All my slash commands are duped, first is the newest version of the command, second is some outdated one. Preview

I'm assuming it is related to slash command registering, so here it is:

const guild = await client.guilds.cache
            .get("836212492769165363")

        guild.commands.set(arrayOfSlashCommands).then((cmd) => {
          const getRoles = (commandName) => {
            const permissions = arrayOfSlashCommands.find(x => x.name === commandName).userPermissions;

            if(!permissions) return null;
            return guild.roles.cache.filter(x => x.permissions.has(permissions) && !x.managed)
          }

          const fullPermissions = cmd.reduce((accumulator, x) => {
            const roles = getRoles(x.name);
            if(!roles) return accumulator;

            const permissions = roles.reduce((a, v) => {
              return [
                ...a,
                {
                  id: v.id, 
                  type: 'ROLE',
                  permission: true,
                },
              ]
            }, [])
            return [
              ...accumulator,
              {
                id: x.id,
                permissions,
              }
            ]
          }, [])
          guild.commands.permissions.set({ fullPermissions }).catch((e) => console.log(e))
        })

CodePudding user response:

Try restarting your bot using this code:

client.application.commands.set([])

Or if you have the guild you can do this:

guild.commands.set([])

This might take some time to finish but it will work. It will clear all the slash commands so you can put them back without duplicating. From what I see, you have both Guild commands and application commands

CodePudding user response:

Global and guild commands are not the same.

Explanation


Global and guild commands are 2 different kinds of slash commands stored in different places.
They both have the limit of 100 and have their own ratelimits.

So what's the difference?


  • Global commands are visible to all guilds and users (including DMs).
  • Guild commands on the other hand, is server-specific.

Demonstration


Imagine you have 2 servers, one called A and one called B.

Now, you registered 2 guild commands inside A. Those 2 commands would not appear on B.

But if you register another 2 global commands, this would appear on both servers and including DMs.

What happened to my code then?


You registered both global and guild commands and they both have the same configuration.
That's the reason they all appeared duplicated.


I hope that this brief explaination made you understand the intentions of 2 kinds of slash commands.
If you have any more questions, use comments below this answer.

  • Related