問題描述
所以我已經在 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"是不是文件做任何事情(如果我錯了,請發表評論!).
回顧一下我為修復我的應用程序所做的工作:
- 將引擎說明符添加到 package.json
- 將 .npmignore 添加到根目錄(是否要添加,由您決定)
- 提交節點模塊文件夾并將其推送到 Github 頁面.
- 通過 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:
- Add the engine specifiers to package.json
- Add .npmignore to the root directory (up to you if you want to add it)
- Commit and push the node modules folder to the Github page as well.
- 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模板網!