Discord.js DiscordAPIError: Invalid Form Body 0.permissions: Must be 10 or fewer in length


I was going to run my bot on a bigger server than the test server and after I re-registered slash commands to the bigger server, the error output:

/home/runner/UnfortunateDistortedEngine/node_modules/discord.js/src/rest/RequestHandler.js:349
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Invalid Form Body
0.permissions: Must be 10 or fewer in length.
1.permissions: Must be 10 or fewer in length.
2.permissions: Must be 10 or fewer in length.
3.permissions: Must be 10 or fewer in length.
4.permissions: Must be 10 or fewer in length.
5.permissions: Must be 10 or fewer in length.
6.permissions: Must be 10 or fewer in length.
7.permissions: Must be 10 or fewer in length.
8.permissions: Must be 10 or fewer in length.
9.permissions: Must be 10 or fewer in length.
10.permissions: Must be 10 or fewer in length.
    at RequestHandler.execute (/home/runner/UnfortunateDistortedEngine/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (/home/runner/UnfortunateDistortedEngine/node_modules/discord.js/src/rest/RequestHandler.js:50:14) {
  method: 'put',
  path: '/applications/873528943758692352/guilds/836212492769165363/commands/permissions',
  code: 50035,
  httpStatus: 400,
  requestData: {
    json: [
      {
        id: '914601275201576970',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576971',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576972',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576973',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576974',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576975',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576976',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576977',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576978',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275201576979',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275298029588',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '870019089488298105', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '875303313560727552', permission: true, type: 1 },
          { id: '875302171128770601', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '863650251478007818', permission: true, type: 1 },
          { id: '885136706330832926', permission: true, type: 1 },
          { id: '881465412112498689', permission: true, type: 1 },
          { id: '836215269243486239', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '860251609812172820', permission: true, type: 1 },
          { id: '836214626617655296', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 },
          { id: '859888824242798612', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275298029589',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275298029590',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275298029591',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '859507507596230736', permission: true, type: 1 },
          { id: '859471924753072188', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275298029592',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '836214627243262002', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 }
        ]
      },
      {
        id: '914601275373551717',
        permissions: [
          { id: '836215354602029076', permission: true, type: 1 },
          { id: '859878718599987200', permission: true, type: 1 },
          { id: '836214626923315221', permission: true, type: 1 },
          { id: '869931180236083230', permission: true, type: 1 }
        ]
      }
    ],
    files: []
  }
}

My slash commands handler where I re-registered the guild.

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 })
        })

I understand that it is related with the second last line: guild.commands.permissions.set({ fullPermissions }) , but how do I fix it?

I’m confused, what do I say else.

Source: JavaSript – Stack Overflow

November 28, 2021
Category : News
Tags: bots | discord | discord.js | javascript | node.js

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.