【发布时间】: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。
标签: javascript node.js discord discord.js bots