最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord.js v13: Slash commands are duplicated - Stack Overflow

programmeradmin3浏览0评论

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

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

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

        guildmands.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,
              }
            ]
          }, [])
          guildmands.permissions.set({ fullPermissions }).catch((e) => console.log(e))
        })

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

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))
        })
Share Improve this question edited Dec 1, 2021 at 7:14 Zsolt Meszaros 23.2k19 gold badges57 silver badges68 bronze badges asked Nov 30, 2021 at 9:34 8less8less 812 gold badges5 silver badges21 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 10

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.

A fix?


There's a way to reset all your guild and global commands.
By using the following code below, it will reset guild commands immediately.
However, you'll have to wait ~1 hour for global commands to update.

    const guild = client.guilds.cache.get("<guild id>");

    // This takes ~1 hour to update
    client.application.commands.set([]);
    // This updates immediately
    guild.commands.set([]);

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

Simple fix: Kick your bot then re-invite it, worked for me :D

发布评论

评论列表(0)

  1. 暂无评论