无法在heroku上托管discord bot(js)
Posted
技术标签:
【中文标题】无法在heroku上托管discord bot(js)【英文标题】:Cant host discord bot (js) on heroku 【发布时间】:2020-05-13 19:42:23 【问题描述】:我正在尝试在 heroku 上托管一个机器人(使用 node 和 discord js 编写)。机器人本身正在运行,因为我可以在本地运行它而没有问题,但 heroku 似乎不喜欢它。每次尝试部署它时,我都会遇到相同的错误。我已将 Procfile 文件更改为工作程序而不是 Web 应用程序,我已推送所有内容 + 重新启动,但似乎无法使其正常工作。有什么帮助吗?
2020-01-28T11:31:46.007810+00:00 heroku[worker.1]: State changed from crashed to starting
2020-01-28T11:31:48.995011+00:00 heroku[worker.1]: Starting process with command `node index.js`
2020-01-28T11:31:49.818228+00:00 heroku[worker.1]: State changed from starting to up
2020-01-28T11:31:52.030152+00:00 heroku[worker.1]: State changed from up to crashed
2020-01-28T11:31:52.006456+00:00 heroku[worker.1]: Process exited with status 0
2020-01-28T11:31:51.886594+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Error: An invalid token was provided.
2020-01-28T11:31:51.886618+00:00 app[worker.1]: at /app/node_modules/discord.js/src/client/rest/RESTMethods.js:34:54
2020-01-28T11:31:51.886621+00:00 app[worker.1]: at new Promise (<anonymous>)
2020-01-28T11:31:51.886623+00:00 app[worker.1]: at RESTMethods.login (/app/node_modules/discord.js/src/client/rest/RESTMethods.js:33:12)
2020-01-28T11:31:51.886625+00:00 app[worker.1]: at Client.login (/app/node_modules/discord.js/src/client/Client.js:280:30)
2020-01-28T11:31:51.886627+00:00 app[worker.1]: at Object.<anonymous> (/app/index.js:45:8)
2020-01-28T11:31:51.886629+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:955:30)
2020-01-28T11:31:51.886631+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
2020-01-28T11:31:51.886633+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:811:32)
2020-01-28T11:31:51.886635+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:723:14)
2020-01-28T11:31:51.886637+00:00 app[worker.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
2020-01-28T11:31:51.887556+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(). (rejection id: 3)
2020-01-28T11:31:51.887666+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.
【问题讨论】:
你好,检查你的机器人令牌UnhandledPromiseRejectionWarning: Error: An invalid token was provided.
结果证明 gitignore 文件阻止了 .env 文件被推送,这就是机器人崩溃的原因。谢谢
【参考方案1】:
仅凭错误很难知道确切的问题,但我认为您可能为机器人提供了错误的令牌,请检查您是否没有忽略包含令牌的文件。 如果您使用 .env 文件作为令牌,那么您可以在 Heroku 上的应用程序上定义环境变量。
【讨论】:
以上是关于无法在heroku上托管discord bot(js)的主要内容,如果未能解决你的问题,请参考以下文章
基于 Python 的 Discord Bot 在本地工作,但从未在 heroku 上托管