discord.js斜杠命令api加载错误



我正试图为我的机器人创建一个/config <subcommand>系统,但它给了我一个斜杠命令体错误。这是命令的当前正文

name: 'config',
description: "The config system for the bot",
userPermissions: ['MANAGE_GUILD'],
options: [
{
name: 'prefix',
description: "Set a different prefifor the server",
type: "SUB_COMMAND",
options: [
{name: "new-prefix", description: "The new prefix that you want to set", type: "STRING", required: true}
]
}
]

错误为

DiscordAPIError[50035]: Invalid Form Body
0.options[0].options[0].type[NUMBER_TYPE_COERCE]: Value "STRING" is not int.
0.options[0].type[NUMBER_TYPE_COERCE]: Value "SUB_COMMAND" is not int.

我在之前从未遇到过这个错误

当您使用原始json注册命令时,选项的类型必须是整数,而不是字符串
为什么?因为Discord API接受整数,而不是字符串
如本文所述,每个类型都有一个关联的id整数,这是您必须使用的,而不是字符串
在您的情况下,type: "SUB_COMMAND"应该是type: 1

为什么选项类型在discord.js文档中被记录为字符串?因为他们把它做成字符串是为了提高代码的可读性。自由党确实";转换";在请求API之前,将这些字符串设置为int。但是在这种情况下,您使用的是原始json。

您可以在Discord Developer Documentation 中检查其他应用程序命令选项类型

最新更新