简体   繁体   中英

Reference error “x” is not defined. when running commands

I'm doing my first discord bot from a github repository. It connects to discord, and logs into the server, but won't respond to !help commands etc. It's not my code so I'm not super familiar with it, but the code for the commands seems to be fine

if (command.content === '!create' && !game) {
  createGame(command)
} else if (command.content === '!start' && game && !game.started) {
  command.delete()
  game.start()
} else if (command.content === '!help') {
  command.channel.send(`!create: Create a new game\n!start: Start the game previously created`)
}if (message.content === 'restartthebot') {
  if (message.author.id !== 'Owners ID') return;
  message.channel.send('Restarted.').then(() => {
  process.exit(1);
})
};


I get this error message in my terminal console

(node:2611) UnhandledPromiseRejectionWarning: ReferenceError: command is not defined
    at Client.<anonymous> (/Applications/werewolf-discord-master 2/src/index.js:63:3)
    at Client.emit (events.js:327:22)
    at WebSocketManager.triggerClientReady (/Applications/werewolf-discord-master 2/src/node_modules/discord.js/src/client/websocket/WebSocketManager.js:431:17)
    at WebSocketManager.checkShardsReady (/Applications/werewolf-discord-master 2/src/node_modules/discord.js/src/client/websocket/WebSocketManager.js:415:10)
    at WebSocketShard.<anonymous> (/Applications/werewolf-discord-master 2/src/node_modules/discord.js/src/client/websocket/WebSocketManager.js:197:14)
    at WebSocketShard.emit (events.js:315:20)
    at WebSocketShard.checkReady (/Applications/werewolf-discord-master 2/src/node_modules/discord.js/src/client/websocket/WebSocketShard.js:475:12)
    at WebSocketShard.onPacket (/Applications/werewolf-discord-master 2/src/node_modules/discord.js/src/client/websocket/WebSocketShard.js:447:16)
    at WebSocketShard.onMessage (/Applications/werewolf-discord-master 2/src/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/Applications/werewolf-discord-master 2/src/node_modules/ws/lib/event-target.js:132:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2611) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2611) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

any help would be much appreciated as I'm on a bit of a time crunch here.

instead of command.content make it message.content to make it work as you havent defined command and please please dont copy code.

if(message.content === "!help" ........

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