生产中的不和bot UnhandledPromiseRejectionWarning (HEROKU)



我将我的不和机器人部署到Heroku,但它给出了未经处理的承诺拒绝的错误以下是日志

2021-09-10T20:50:26.000000+00:00 app[api]: Build started by user codertanishq@gmail.com
2021-09-10T20:50:45.558185+00:00 app[api]: Deploy c608c194 by user codertanishq@gmail.com
2021-09-10T20:50:45.558185+00:00 app[api]: Release v11 created by user codertanishq@gmail.com
2021-09-10T20:50:46.000000+00:00 app[api]: Build succeeded
2021-09-10T20:50:46.978335+00:00 heroku[web.1]: State changed from crashed to starting
2021-09-10T20:50:48.877754+00:00 heroku[web.1]: Starting process with command `npm start`
2021-09-10T20:50:51.529490+00:00 app[web.1]: 
2021-09-10T20:50:51.529505+00:00 app[web.1]: > start@1.0.0 start /app
2021-09-10T20:50:51.529506+00:00 app[web.1]: > node ./src/bot.js
2021-09-10T20:50:51.529506+00:00 app[web.1]: 
2021-09-10T20:50:51.762757+00:00 app[web.1]: (node:22) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined
2021-09-10T20:50:51.762758+00:00 app[web.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:172:15)
2021-09-10T20:50:51.762758+00:00 app[web.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:176:19)
2021-09-10T20:50:51.762758+00:00 app[web.1]:     at RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:50:25)
2021-09-10T20:50:51.762759+00:00 app[web.1]:     at async WebSocketManager.connect (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:128:9)
2021-09-10T20:50:51.762759+00:00 app[web.1]:     at async Client.login (/app/node_modules/discord.js/src/client/Client.js:245:7)
2021-09-10T20:50:51.762759+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-10T20:50:51.763064+00:00 app[web.1]: (node:22) 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: 2)
2021-09-10T20:50:51.763091+00:00 app[web.1]: (node:22) [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.
2021-09-10T20:50:51.847328+00:00 heroku[web.1]: Process exited with status 0
2021-09-10T20:50:51.902780+00:00 heroku[web.1]: State changed from starting to crashed

您必须升级您的节点版本。您可以在您的package.json中添加以下内容:

"engines": {
"node": "16.9.1",
}

重新部署你的项目,它会工作的

Discord.js v13需要AbortController才能运行,但它只在node版本16及以上才引入。您有两个选项来修复此错误:

  • 将heroku上的节点版本升级到16或以上

  • 为你的AbortController使用一个polyfill,AbortController-polyfill是一个包,你可以这样使用它:

const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');
global.AbortController = AbortController;

最新更新