所以我刚刚完成了ban命令的编码,当我想运行机器人程序时,我遇到了一个巨大的错误。我甚至不知道这个错误意味着什么,所以如果你能在寻找解决方案的同时向我解释一下,我将不胜感激。如果你不能,那也没关系。
DiscordAPIError: Invalid Form Body
2.options[2].choices: Choices cannot be configured for this type of option
我找过这个问题,但似乎找不到。有人能帮我拿这个吗?
这是代码:
const { Client, CommandInteraction, MessageEmbed } = require('discord.js');
module.exports = {
name: 'ban',
description: 'Bans the target member',
permission: 'ADMINISTRATOR',
options: [{
name: 'target',
description: 'Select a target to ban.',
type: 'USER',
required: true,
},
{
name: 'reason',
description: 'Provide a reason for this ban.',
type: 'STRING',
required: true,
},
{
name: 'messages',
description: 'Choose one of the choices.',
type: 'USER',
required: true,
choices: [{
name: 'Don't delete any',
value: '0'
},
{
name: 'Previous 7 days.',
value: '7'
}
]
},
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
*/
async execute(client, interaction) {
const { options, member } = interaction;
const Target = options.getMember('target');
if (Target.id === member.id)
return interaction.reply({
embeds: [new MessageEmbed().setColor('RED').setDescription(`⛔ | You can't ban yourself.`)]
})
if (Target.permissions.has('ADMINISTRATOR'))
return interaction.reply({
embeds: [new MessageEmbed().setColor('RED').setDescription(`⛔ | You can't an administrator.`)]
})
const Reason = options.getString('reason');
if (Reason.length > 512)
return interaction.reply({
embeds: [new MessageEmbed().setColor('RED').setDescription(`⛔ | The reason can't exceed 512 characters.`)]
})
const Amount = options.getString('messages')
Target.ban({
days: Amount,
reason: Reason
})
interaction.reply({
embeds: [new MessageEmbed().setColor('GREEN').setDescription(`✅ | **${target.user.username}** has been banned from the server.`)]
})
}
};
USER
类型不能有选择。看起来您需要STRING
。例如,您的代码如下所示:
const { Client, CommandInteraction, MessageEmbed } = require('discord.js');
module.exports = {
name: 'ban',
description: 'Bans the target member',
permission: 'ADMINISTRATOR',
options: [{
name: 'target',
description: 'Select a target to ban.',
type: 'USER',
required: true,
},
{
name: 'reason',
description: 'Provide a reason for this ban.',
type: 'STRING',
required: true,
},
{
name: 'messages',
description: 'Choose one of the choices.',
type: 'STRING',
required: true,
choices: [{
name: 'Don't delete any',
value: '0'
},
{
name: 'Previous 7 days.',
value: '7'
}
]
},
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
*/
async execute(client, interaction) {
const { options, member } = interaction;
const Target = options.getMember('target');
if (Target.id === member.id)
return interaction.reply({
embeds: [new MessageEmbed().setColor('RED').setDescription(`⛔ | You can't ban yourself.`)]
})
if (Target.permissions.has('ADMINISTRATOR'))
return interaction.reply({
embeds: [new MessageEmbed().setColor('RED').setDescription(`⛔ | You can't an administrator.`)]
})
const Reason = options.getString('reason');
if (Reason.length > 512)
return interaction.reply({
embeds: [new MessageEmbed().setColor('RED').setDescription(`⛔ | The reason can't exceed 512 characters.`)]
})
const Amount = options.getString('messages')
Target.ban({
days: Amount,
reason: Reason
})
interaction.reply({
embeds: [new MessageEmbed().setColor('GREEN').setDescription(`✅ | **${target.user.username}** has been banned from the server.`)]
})
}
};
请参阅此处以获取参考。
希望这能有所帮助