未定义参考错误“x”。运行命令时

Posted

技术标签:

【中文标题】未定义参考错误“x”。运行命令时【英文标题】:Reference error "x" is not defined. when running commands 【发布时间】:2021-04-16 21:18:53 【问题描述】:

我正在从 github 存储库做我的第一个不和谐机器人。它连接到不和谐,并登录到服务器,但不会响应!help 命令等。 这不是我的代码,所以我对它不是很熟悉,但是命令的代码似乎很好

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


我在终端控制台中收到此错误消息

(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.

任何帮助将不胜感激,因为我在这里有点时间紧张。

【问题讨论】:

您必须包含更多关于尝试做什么的详细信息。 Stack Overflow 不是代码编写服务。我们总是乐于帮助和支持新的编码员,但您需要先帮助自己。您应该尝试自己编写代码。请阅读How to create a Minimal, Reproducible Example 和How do I ask a good question?。 我们不知道,因为我们无法重现问题。而且 Java ≠ javascript 【参考方案1】:

而不是 command.content 使其成为 message.content 以使其工作,因为您尚未定义命令,请不要复制代码。

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

【讨论】:

以上是关于未定义参考错误“x”。运行命令时的主要内容,如果未能解决你的问题,请参考以下文章

运行排毒测试命令时无法读取未定义的属性“类型”

运行播放命令时未定义的歌曲

自定义管理命令在虚拟环境中抛出未找到模块错误

运行生成脚手架命令时出现未定义的方法“组”错误

Swift 测试给出错误“架构 x86_64 的未定义符号”

通过命令提示符运行python程序时未找到模块错误