Discord 机器人不以 heroku 开头

Discord bot not starting with heroku

所以我已经在 heroku 上托管我的 bot 一段时间了,它工作得很好,但我最近又暂时移动到自我托管,因为我不得不更新到 discord.js v13,但现在我已完成更改,并尝试在 heroku 上重新托管机器人,但出现此错误:

(node:4) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined

2021-08-08T20:30:17.770796+00:00 app[Worker.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:172:15)

2021-08-08T20:30:17.770796+00:00 app[Worker.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:176:19)

2021-08-08T20:30:17.770797+00:00 app[Worker.1]:     at RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:50:25)

2021-08-08T20:30:17.770797+00:00 app[Worker.1]:     at processTicksAndRejections (internal/process/task_queues.js:95:5)

2021-08-08T20:30:17.770798+00:00 app[Worker.1]:     at async WebSocketManager.connect (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:128:9)

2021-08-08T20:30:17.770798+00:00 app[Worker.1]:     at async Client.login (/app/node_modules/discord.js/src/client/Client.js:245:7)

2021-08-08T20:30:17.770799+00:00 app[Worker.1]: (Use `node --trace-warnings ...` to show where the warning was created)

2021-08-08T20:30:17.770962+00:00 app[Worker.1]: (node:4) 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-08-08T20:30:17.771045+00:00 app[Worker.1]: (node:4) [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.

我不明白发生了什么,我认为可能导致这种情况的唯一变化是我制作了一个事件处理程序,现在我将事件放在它们自己的文件中,例如命令,但我不确定如果这与此错误有关,我真的希望您能提供帮助。

我最近也遇到了这个错误。

Discord.js 版本 13 在节点 16.6.1 上运行,但是默认的 Heroku 节点版本是 14.x.

这意味着我们必须指定我们希望 Heroku 在其上构建我们的应用程序的版本。

在package.json中添加

"engines": {
   "node": "16.x",
   "npm": "7.x"
}

参考:https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

这向 buildpack 指定我们需要使用最新版本的节点 16 和 npm 7。

然而,在我添加之后,我遇到了一个部署错误,并参考了这个stack overflow question

那里的答案说要在您的根文件夹中添加一个空的“.npmignore”文件,所以我就这样做了。但是,将所有内容推送到 Github 后,我仍然收到相同的部署错误。

它说临时目录中的文件“node.exe”丢失了。 经过反复试验,我决定提交并将“node_modules/”目录推送到 Github(这花了一些时间),因为(抱歉我没有复制构建日志)文件“node.exe”驻留在“node_modules/”目录中,然后重新部署我的应用程序,它成功了!

总而言之,这有点迂回,因为我不知道“.npmignore”文件是否有任何作用(如果我错了,请发表评论!)。

回顾一下我为修复我的应用程序所做的工作:

  1. 将引擎说明符添加到 package.json
  2. 在根目录下添加.npmignore(加不加由你决定)
  3. 提交节点模块文件夹并将其推送到 Git 中心页面。
  4. 通过 Github
  5. 部署

仅供参考:我不知道这是否适用于 Heroku Git...如果可行,请在评论中告诉我。

我尝试了将仅具有节点版本(没有 npm 版本)的“引擎”属性 添加到 package.json 的解决方案,它对我有用。这样您就不必将大型节点模块推送到 GitHub.