Discord.js DiscordAPIError:无效的表单正文 0.permissions:长度必须为 10 或更少
Posted
技术标签:
【中文标题】Discord.js DiscordAPIError:无效的表单正文 0.permissions:长度必须为 10 或更少【英文标题】:Discord.js DiscordAPIError: Invalid Form Body 0.permissions: Must be 10 or fewer in length 【发布时间】:2022-01-05 20:15:41 【问题描述】:我打算在比测试服务器更大的服务器上运行我的机器人,在我将斜杠命令重新注册到更大的服务器后,错误输出:
/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: []
我重新注册公会的斜线命令处理程序。
const slashCommands = await globPromise(
`$process.cwd()/slash/*/*.js`
);
const arrayOfSlashCommands = [];
slashCommands.map((value) =>
const file = require(value);
if (!file?.name) return;
client.slashCommands.set(file.name, file);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
if(file.userPermissions) file.defaultPermission = false;
arrayOfSlashCommands.push(file);
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 )
)
我知道它与倒数第二行有关:guild.commands.permissions.set( fullPermissions )
,但我该如何解决?
我很困惑,我还能说什么。
【问题讨论】:
什么是arrayOfSlashCommands
?
嘿@MrMythical,我编辑了代码。
@MrMythical 我假设这是因为角色
【参考方案1】:
简答
除了进行内部权限检查之外,没有其他解决方案。 这是目前最好的方法,除非 Discord 实施新的权限系统。
长答案
说明
(n).permissions: Must be 10 or fewer in length
基本上,Discord API 告诉您,您只能在一个斜杠命令中为用户或角色设置 10 个权限。
解决方案
解决此问题的唯一方法是等待 Discord 实施正确的权限系统,否则您需要实施内部权限检查。
它已经被请求了!但是...
discord-api-docs repo 已经有一个关于新权限系统的功能请求,就在here。虽然,他们暂时跳过了这个想法,但仍然在列表中注明。
【讨论】:
以上是关于Discord.js DiscordAPIError:无效的表单正文 0.permissions:长度必须为 10 或更少的主要内容,如果未能解决你的问题,请参考以下文章
Discord 错误错误 Discord.js 中的无效令牌
Discord 仅识别 discord.js 中的“ping”命令
错误“const Discord = require(discord.js) ^ ReferenceError: discord is not defined”
(Discord 机器人)当用户加入 Discord 服务器(discord.js)时,如何发送欢迎消息?