我正在尝试在不和谐中制作斜杠命令处理程序.js v13



我正试图更改我的命令处理程序以使用斜杠命令,但在尝试打开bot时,我遇到了Invalid Form Body错误。我不想切换处理程序,因为这是我在所有机器人上使用的,但我也无法修复错误。我正在使用discord js v13

这是我当前的命令处理程序(index.js(:

const pComandos = fs.readdirSync('Comandos');
client.commands = new Discord.Collection();
client.description = new Discord.Collection();
for (const folder of pComandos) {
const file = fs.readdirSync('Comandos/' + folder);
for (const comando of file) {
let cmd = require(`./Comandos/${folder}/${comando}`);
commandsArray = [];
console.log(chalk.green(`[ C ] O comando ` + chalk.bold(comando) + ` foi carregado!`))
client.commands.set(cmd.help.name, cmd)
if (cmd.help.description) {
cmd.desc = true
cmd.help.description.forEach(desc => client.commands.set(desc, cmd))
}
client.commands.set(cmd)
commandsArray.push(cmd.help.name);
if (cmd.init) cmd.init(client)
client.on("ready", async() => {
const server = await client.guilds.cache.get("892210305558532116")
server.commands.set(commandsArray)
})
}
}

Comandos/uteis/ping.js

const discord = require("discord.js");
exports.run = async (client, message, args) => {

var latency = Date.now() - message.createdTimestamp
message.reply(`<:emoji_3:892431734203891722> | My ping is: ${client.ws.ping}.n🗺 | Timezone: ${process.env.TZ}`);
};
exports.help = {
name: "ping",
description: ["p"]
};

错误:

DiscordAPIError: Invalid Form Body
0.name: This field is required
at RequestHandler.execute (C:UserswhashOneDriveDocumentosoptiPC-BOT2node_modulesdiscord.jssrcrestRequestHandler.js:349:13)     
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:UserswhashOneDriveDocumentosoptiPC-BOT2node_modulesdiscord.jssrcrestRequestHandler.js:50:14)   
at async GuildApplicationCommandManager.set (C:UserswhashOneDriveDocumentosoptiPC-BOT2node_modulesdiscord.jssrcmanagersApplicationCommandManager.js:146:18) {
method: 'put',
path: '/applications/909489088904712223/guilds/892210305558532116/commands',
code: 50035,
httpStatus: 400,
requestData: {
json: [
{
name: undefined,
description: undefined,
type: undefined,
options: undefined,
default_permission: undefined
}
],
files: []
}
}

您需要使用一个ApplicationCommandData对象。

取而代之的是:

commandsArray.push(cmd.help.name)

这样做:

commandsArray.push({
name: cmd.help.name,
description: cmd.help.description.join("") // or whatever description you want
})

最新更新