DiscordJS和Linux的屏幕

时间:2019-02-16 15:50:37

标签: node.js discord.js

我遇到了Discordjs的问题,我不理解。我在Linux屏幕上运行“ node main.js”,分离它,进入睡眠状态,当我回来时,它崩溃了。你能开导我吗?

    # screen -r BotApex
(node:6559) [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.
events.js:180
    throw err; // Unhandled 'error' event
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
    at Client.emit (events.js:178:17)
    at WebSocketConnection.onError (/root/ApexLegendsSnipeBot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
    at WebSocket.onError (/root/ApexLegendsSnipeBot/node_modules/ws/lib/event-target.js:128:16)
    at WebSocket.emit (events.js:189:13)
    at _receiver.cleanup (/root/ApexLegendsSnipeBot/node_modules/ws/lib/websocket.js:211:14)
    at Receiver.cleanup (/root/ApexLegendsSnipeBot/node_modules/ws/lib/receiver.js:557:13)
    at WebSocket.finalize (/root/ApexLegendsSnipeBot/node_modules/ws/lib/websocket.js:206:20)
    at TLSSocket.emit (events.js:189:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)

1 个答案:

答案 0 :(得分:0)

好像您的机器人在您离开时遇到了error事件。如果您不处理错误事件,它们通常会使您的机器人崩溃。为了防止漫游器崩溃,只需添加一个错误侦听器:

client.on("error", info => {
  console.log('Error event:\n' + JSON.stringify(info));
  // handle the error here
});

请记住,由于某种原因调用了错误事件,之后应处理错误。