我如何获得由discord bot maker创建的Discord Bot在Heroku上工作

时间:2018-08-29 14:15:51

标签: node.js heroku bots discord discord.js

因此,该机器人在本地运行时完美运行,但是当我在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 }`);
});

1 个答案:

答案 0 :(得分:0)

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

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