我有一个读写和读取json文件的不和谐的机器人,我想添加命令处理程序,但是当我添加命令处理程序时,如果我添加的命令数超过2并尝试运行命令,我只能添加2条命令,但出现此错误讯息:
C:\Users\alier\Desktop\sb\index.js:428
bot.commands.get('try').execute(bot, message, args, trymessage, tryrole);
TypeError: Cannot read property 'execute' of undefined
at Client.<anonymous> (C:\Users\alier\Desktop\sb\index.js:428:49)
at Client.emit (events.js:321:20)
at MessageCreateAction.handle (C:\Users\alier\Desktop\sb\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\alier\Desktop\sb\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\alier\Desktop\sb\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\alier\Desktop\sb\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\alier\Desktop\sb\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\alier\Desktop\sb\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:321:20)
at Receiver.receiverOnMessage (C:\Users\alier\Desktop\sb\node_modules\ws\lib\websocket.js:797:20)
我的命令处理程序代码:
const fs = require('fs')
module.exports = {
name: 'trying',
description: "tryingcommandhandler",
execute(bot, message, args, trymessage, tryrole){
code...
}
}
答案 0 :(得分:0)
这是我的discordjs ping命令中的一些代码
const { MessageEmbed, MessageAttachment } = require("discord.js");
module.exports = {
name: "ping",
description: "Ping!",
execute(message, args, client) {
let color = "CENSORED";
const embed = new MessageEmbed()
.setTitle("Ping!")
.setDescription(`:clock11: My Latency is ${Math.round(client.ws.ping)}ms`)
.setColor(color);
message.channel.send(embed);
}
};
因此使用您的代码就可以了
const fs = require('fs');
module.exports = {
name: 'trying',
description: "tryingcommandhandler",
execute(bot, message, args, trymessage, tryrole) {
CODE...
}
};
如果这不起作用,请发表评论,我可以提供更多帮助