首页 > 解决方案 > 我如何获得由 discord bot 制造商创建的 Discord Bot 以在 Heroku 上工作

问题描述

因此,该机器人在本地运行时运行良好,但是当我在 heroku 上运行它时,它给了我一个错误消息:

2018-08-29T13:57:58.295022+00:00 app[web.1]: (node:4) ExperimentalWarning: 
The http2 module is an experimental API.
2018-08-29T13:57:58.732365+00:00 app[web.1]: Bot is ready!
2018-08-29T13:58:55.278962+00:00 heroku[web.1]: Error R10 (Boot timeout) -> 
Web process failed to bind to $PORT within 60 seconds of launch
2018-08-29T13:58:55.278962+00:00 heroku[web.1]: Stopping process with 
SIGKILL
2018-08-29T13:58:55.404294+00:00 heroku[web.1]: Process exited with status 137
2018-08-29T13:58:55.623262+00:00 heroku[web.1]: State changed from starting to crashed

现在,如果我尝试那里的灵魂:

2018-08-29T14:07:46.618465+00:00 heroku[web.1]: Starting process with 
command `node bot.js`
2018-08-29T14:07:48.107034+00:00 heroku[web.1]: Process exited with status 1
2018-08-29T14:07:48.063674+00:00 app[web.1]: /app/bot.js:8
2018-08-29T14:07:48.063700+00:00 app[web.1]: app.listen(PORT, () => {
2018-08-29T14:07:48.063701+00:00 app[web.1]: ^
2018-08-29T14:07:48.063703+00:00 app[web.1]: 
2018-08-29T14:07:48.063704+00:00 app[web.1]: ReferenceError: app is not defined
2018-08-29T14:07:48.063706+00:00 app[web.1]:     at Object.<anonymous> 
(/app/bot.js:8:1)
2018-08-29T14:07:48.063707+00:00 app[web.1]:     at Module._compile 
(module.js:652:30)
2018-08-29T14:07:48.063709+00:00 app[web.1]:     at 
Object.Module._extensions..js (module.js:663:10)
2018-08-29T14:07:48.063711+00:00 app[web.1]:     at Module.load 
(module.js:565:32)
2018-08-29T14:07:48.063713+00:00 app[web.1]:     at tryModuleLoad 
(module.js:505:12)
2018-08-29T14:07:48.063714+00:00 app[web.1]:     at Function.Module._load 
(module.js:497:3)
2018-08-29T14:07:48.063716+00:00 app[web.1]:     at Function.Module.runMain 
(module.js:693:10)
2018-08-29T14:07:48.063718+00:00 app[web.1]:     at startup 
(bootstrap_node.js:191:16)
2018-08-29T14:07:48.063720+00:00 app[web.1]:     at bootstrap_node.js:612:3
2018-08-29T14:07:48.120800+00:00 heroku[web.1]: State changed from starting 
to crashed

还有我添加的脚本:https ://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`Our app is running on port ${ PORT }`);
});

标签: node.jsherokubotsdiscorddiscord.js

解决方案


嗯...似乎错误是app未定义的。

我假设您使用的是 JS Express 库,因此请确保正确安装了 Express 库。仔细检查您是否将其正确导入程序,并确保定义 const app = express();


推荐阅读