Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何让Discord Bot maker创建的Discord Bot在Heroku上运行_Node.js_Heroku_Bots_Discord_Discord.js - Fatal编程技术网

Node.js 如何让Discord Bot maker创建的Discord Bot在Heroku上运行

Node.js 如何让Discord Bot maker创建的Discord Bot在Heroku上运行,node.js,heroku,bots,discord,discord.js,Node.js,Heroku,Bots,Discord,Discord.js,因此,当在本地运行bot时,它可以完美地工作,但当我在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.278

因此,当在本地运行bot时,它可以完美地工作,但当我在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

嗯……似乎错误在于没有定义
app

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

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