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...
}
}
nameproperty in your command file has to match the name in theget()function. - Lioness100