简体   繁体   中英

discord bot command handler issue

I have a discord bot that write and read json files and I want to add command handler but when I Add a Command handler I only can add 2 commands if i add more than 2 and try to run the command I get this error message:

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)

My command handler code:

const fs = require('fs')
module.exports = {
    name: 'trying',
    description: "tryingcommandhandler",
    execute(bot, message, args, trymessage, tryrole){
     code...
   
  
}
} 

Here is some code from my discordjs ping command

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);
  }
};

so using your code it would be

const fs = require('fs');
module.exports = {
  name: 'trying',
  description: "tryingcommandhandler",
  execute(bot, message, args, trymessage, tryrole) {
  CODE...
  }
};

if this doesn't work please comment and I can help some more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM