javascript - Discord.js failing to execute
问题描述
I ran the example code from the discord.js documentation, with my bots token, and it fails to execute with this error:
(node:9880) UnhandledPromiseRejectionWarning: AbortError: The user aborted a request. at RequestHandler.execute (/home/pi/node_modules/discord.js/src/rest/RequestHandler.js:107:21) at process._tickCallback (internal/process/next_tick.js:68:7) (node:9880) 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(). (rejection id: 2) (node:9880) [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.
I have recieved this error on my rpi and my pc
解决方案
As per this github comment, it seems that this is caused by requests taking too long to resolve, and Discord.js simply aborts it to avoid getting stuck.
If this causes an issue by causing your bot to go offline, you can add the following line to catch all unhandled promise rejections in your code:
process.on("unhandledRejection", error => console.error("Promise rejection:", error);
This not only will stop your bot from crashing, but will also provide more detailed error information, which you can further investigate here.
推荐阅读
- c - 不破坏复制/粘贴的子类编辑控件
- swift - 右键单击 UIKitForMac 的 UIButton(催化剂)
- ruby-on-rails - 无法登录会话(Rails)
- python - 动态屏蔽 pandas df 以查找与列表中的字符串匹配的行
- javascript - 单击超链接图像/文本时如何播放声音(仍将您带到超链接网页)
- kubernetes - 我的虚拟机重新启动后,Kubelet 节点设置为 NotReady
- javascript - React Native 在这样的结构中绑定 null 做了什么: someFunction.bind(null, someHook)
- reactjs - 如何从 reactJS 前端点击 Express 后端?
- arm - 为什么 Cortex-M4 在链接器脚本中包含 ARM 到 Thumb 胶水
- python - Pytorch:降低 U-net 模型中的参数