[英]DiscordJS v14 invalid form body
I have been trying to make a slash command with subcommand that sends message to specified channel.我一直在尝试使用将消息发送到指定通道的子命令来创建斜杠命令。 When i try to deploy it, i get:
当我尝试部署它时,我得到:
DiscordAPIError[50035]: Invalid Form Body
options[1][APPLICATION_COMMAND_OPTIONS_TYPE_INVALID]: Sub-command and sub-command group option types are mutually exclusive to all other types
at SequentialHandler.runRequest (D:\projs\cpp\tbot\node_modules\@discordjs\rest\dist\index.js:659:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (D:\projs\cpp\tbot\node_modules\@discordjs\rest\dist\index.js:458:14)
at async REST.request (D:\projs\cpp\tbot\node_modules\@discordjs\rest\dist\index.js:902:22)
at async D:\projs\cpp\tbot\deploy-commands.js:24:16 {
requestBody: { files: undefined, json: [ [Object], [Object] ] },
rawError: {
code: 50035,
errors: { options: [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/752621311494455367/guilds/1039125828790919240/commands'
}
My code:我的代码:
const { SlashCommandBuilder } = require('discord.js');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
module.exports = {
data: new SlashCommandBuilder()
.setName('say')
.setDescription('Make bot say anything the executor wants')
.addSubcommand(subcommand =>
subcommand
.setName('channel')
.setDescription('Says ')
.addChannelOption(option =>
option
.setName('target_channel')
.setDescription('Channel to send message in.')
.setRequired(true)))
.addStringOption(option =>
option
.setName('text')
.setDescription("Message to be sent in specified channel")
.setRequired(true)),
async execute(interaction) {
const channel = interaction.options.getChannel('target_channel');
const text = interaction.options.getString('text');
client.channels.cache.get(channel).send(text);
},
};
I have no clue about it.我对此一无所知。 I didn't find anything about it anywhere.
我在任何地方都没有找到任何关于它的信息。 I expected it to deploy the commands via
node deploy-commands.js
but it resulted in error above.我希望它通过
node deploy-commands.js
,但它导致了上面的错误。
The error is emitted when you attempt to add an option to a command which also has a subcommand.当您尝试向也有子命令的命令添加选项时,会发出错误。 To illustrate this better I've create an ascii table, note how
channel
and text
options are on the same level, which would result in an error.为了更好地说明这一点,我创建了一个 ascii 表,注意
channel
和text
选项如何处于同一级别,这将导致错误。
say
|- channel: SUB_COMMAND
| |- name: STRING
| |- target_channel: TEXTCHANNEL
|- text: STRING
| |- option: STRING
If I've interpreted your code correctly you may want to add the string option to the subcommand, as so:如果我正确地解释了您的代码,您可能希望将字符串选项添加到子命令中,如下所示:
data: new SlashCommandBuilder()
.setName('say')
.setDescription('Make bot say anything the executor wants')
.addSubcommand(subcommand =>
subcommand
.setName('channel')
.setDescription('Says ')
.addStringOption(option =>
option
.setName('text')
.setDescription("Message to be sent in specified channel")
.setRequired(true)
)
.addChannelOption(option =>
option
.setName('target_channel')
.setDescription('Channel to send message in.')
.setRequired(true)
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.