node.js - DiscordJS 和 Linux 的屏幕
问题描述
我遇到了 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)
解决方案
看起来您的机器人error
在您离开时遇到了事件。如果您不处理错误事件,它们通常会使您的机器人崩溃。为了防止机器人崩溃,只需添加一个错误监听器:
client.on("error", info => {
console.log('Error event:\n' + JSON.stringify(info));
// handle the error here
});
请记住,错误事件已因某种原因被调用,您应该在之后处理该错误。
推荐阅读
- python - 如何将抓取的数据写入csv fromat?
- xml - 如何在 xml odoo 中的单个字段上应用多种格式?
- facebook - 来自 Facebook 帖子的 RSS 提要
- r - 从文件输入更新闪亮表
- regex - 正则表达式:匹配没有字母的电话号码
- javascript - 为什么跨源工作人员被阻止,为什么解决方法可以?
- c# - 如何测试属性是否已被声明为“动态”?
- ios - 跨多个 iOS 设备访问图像
- java - 如何在 application.yml 中定义一个 bean?
- delphi - 在 DBGrid 列中运行时将 RangeArray(1.00-11.59) 内的条目号 (1.30) 自动转换为 (1:30)