为什么不和谐.js?command.set(command) 不起作用?



我正在开发一个不和谐机器人,我注册斜杠命令是错误的,我想用。set函数覆盖它,但它在我没有编辑的文件中给了我一个错误。

index.js代码:

client.on('messageCreate', async (message) =>{
if(message.content.toLowerCase() === "lava.register"){
const data = {
name: "ban",
description: "Banna un utente dal server",
option: [
{
name: "UTENTE",
description: "Specifica l'utente da bannare dal server",
type: "USER",
require: true,
},
{
name: "MOTIVO",
description: "Specifica il motivo del ban",
type: "STRING",
require: true,
}
]
}; 
const comando = await client.guilds.cache.get('957317299289858108')?.commands.set(data);
console.log(comando)
}
})
错误:

data: commands.map(c => this.constructor.transformCommand(c)),
^
TypeError: commands.map is not a function
at GuildApplicationCommandManager.set (/Users/Me/Desktop/VolcanoBot/node_modules/discord.js/src/managers/ApplicationCommandManager.js:157:22)
at Client.<anonymous> (/Users/yihanzhou/Desktop/VolcanoBot/index.js:35:87)
at Client.emit (node:events:537:28)
at MessageCreateAction.handle (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/actions/MessageCreate.js:26:14)
at module.exports [as MESSAGE_CREATE] (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:346:31)
at WebSocketShard.onPacket (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:478:22)
at WebSocketShard.onMessage (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:317:10)
at WebSocket.onMessage (/Users/yihanzhou/Desktop/VolcanoBot/node_modules/ws/lib/event-target.js:199:18)
at WebSocket.emit (node:events:537:28)

文件(VolcanoBot/node_modules/discord.js/src/经理/ApplicationCommandManager.js: 157:22)

async set(commands, guildId) {
const data = await this.commandPath({ guildId }).put({
data: commands.map(c => this.constructor.transformCommand(c)),
});
return data.reduce((coll, command) => coll.set(command.id, this._add(command, true, guildId)), new Collection());
}

我该怎么办?

尝试使用client.application.commands.set()设置全局命令。

最新更新