首页 > 解决方案 > 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

标签: javascriptnode.jsdiscord.js

解决方案


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.


推荐阅读