Discord bot 不是从 heroku 开始的

时间:2023-02-10
本文介绍了Discord bot 不是从 heroku 开始的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经在 heroku 上托管了我的机器人一段时间了,它工作得很好,但我最近又临时搬到了自我托管,因为我必须更新到 discord.js v13,但现在我已经完成了有了这些更改,我尝试在 heroku 上重新托管机器人,但它给出了这个错误:

(node:4) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined2021-08-08T20:30:17.770796+00:00 app[Worker.1]: 在 RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:172:15)2021-08-08T20:30:17.770796+00:00 app[Worker.1]: 在 RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:176:19)2021-08-08T20:30:17.770797+00:00 app[Worker.1]: 在 RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:50:25)2021-08-08T20:30:17.770797+00:00 app[Worker.1]: 在 processTicksAndRejections (internal/process/task_queues.js:95:5)2021-08-08T20:30:17.770798+00:00 app[Worker.1]: 在异步 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]: 在异步 Client.login (/app/node_modules/discord.js/src/client/Client.js:245:7)2021-08-08T20:30:17.770799+00:00 app[Worker.1]:(使用`node --trace-warnings ...`显示警告的创建位置)2021-08-08T20:30:17.770962+00:00 app[Worker.1]: (node:4) UnhandledPromiseRejectionWarning: 未处理的承诺拒绝.此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺.要在未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志 `--unhandled-rejections=strict`(请参阅 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).(拒绝编号:2)2021-08-08T20:30:17.771045+00:00 app[Worker.1]: (node:4) [DEP0018] DeprecationWarning:未处理的承诺拒绝已被弃用.将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程.

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

解决方案

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

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

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

在 package.json 中添加

引擎":{节点":16.x",npm":7.x"}

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

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

但是,在我添加之后,我遇到了一个部署错误,并参考了这个 堆栈溢出问题

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

这是说文件node.exe"在临时目录中丢失.经过反复试验,我决定提交并推送node_modules/".到 Github 的目录(这需要一些时间),因为(对不起,我没有复制构建日志)文件node.exe"驻留在node_modules/"中目录,然后重新部署我的应用程序,它工作了!

总而言之,这是一次往返之旅,因为我不知道.npmignore"是不是文件做任何事情(如果我错了,请发表评论!).

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

  1. 将引擎说明符添加到 package.json
  2. 将 .npmignore 添加到根目录(是否要添加,由您决定)
  3. 提交节点模块文件夹并将其推送到 Github 页面.
  4. 通过 Github 部署

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

So i have hosted my bot on heroku for some time now, and it worked just fine, but i recently moved, temporarly, to self hosting again cause i had to update to discord.js v13, but now i'm done with the changes, and i tried to re-host the bot on heroku, but it gives this error:

(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.

I don't understand what is happening, the only change that i think could cause this is the fact that i made an event handler and i now put events in their own files like commands, but i'm not sure if that has something to do with this error, i really hope you can help.

解决方案

I recently came across this error too.

Discord.js version 13 runs on node 16.6.1, however, the default Heroku node version is 14.x.

That means we have to specify the version that we want Heroku to build our app on.

In package.json add

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

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

This specifies to the buildpack that we need to use the latest version of node 16 and npm 7.

However, after I added that, I came across a deployment error, and referred to this stack overflow question

The answer there stated to add an empty ".npmignore" file in your root folder, and so I did that. However, after pushing everything to Github, I still received the same deployment error.

It was saying that the file "node.exe" in a temp directory was missing. After some trial and error, I decided to commit and push the "node_modules/" directory to the Github (that took some time), because (sorry I didn't copy the build logs) the file "node.exe" resided in the "node_modules/" directory, and then re-deployed my application, and it worked!

All in all it was kind of a roundhouse trip, because I don't know if the ".npmignore" file does anything (please comment if I'm wrong!).

To recap what I did to fix my application:

  1. Add the engine specifiers to package.json
  2. Add .npmignore to the root directory (up to you if you want to add it)
  3. Commit and push the node modules folder to the Github page as well.
  4. Deploy through Github

FYI: I don't know if this works on Heroku Git... tell me in the comments if it works.

这篇关于Discord bot 不是从 heroku 开始的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:Discord.js 用户状态自定义 下一篇:如何在 Discord.js 中添加错误消息?

相关文章

最新文章