【发布时间】:2021-02-19 21:28:59
【问题描述】:
我一直在尝试使用heroku 制作机器人,但在部署它时出现此错误:Web process failed to bind to $PORT within 60 seconds of launch。
我做了很多事情,包括尝试app.listen(process.env.PORT || 5000),但我收到了错误app is not defined。
这是我的 index.js:
const discord = require('discord.js');
const bot = new discord.Client();
const token = 'Nzc0MjQxOTAyMzE2MjI0NTIy.X6U69g.sjmAievx3II561tvYfOVy72an1k';
bot.on('ready', () =>{
console.log('This bot is online');
})
bot.on('message', message=>{
if(message.content === "im lost"){
message.channel.send('You should try finding your way through the welcome channel!')
}
if(message.content === "i need help"){
message.channel.send('Check out the bot-help channel!')
}
})
bot.login(token);
package.json:
{
"name": "compass",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "Alex",
"license": "ISC",
"dependencies": {
"discord.js": "^12.4.1",
"express": "^4.17.1"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/Razdoll/Compass-Host.git"
},
"keywords": [],
"bugs": {
"url": "https://github.com/Razdoll/Compass-Host/issues"
},
"homepage": "https://github.com/Razdoll/Compass-Host#readme",
"description": ""
}
还有heroku日志:
2020-11-07T10:13:06.345403+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-07T10:13:06.144839+00:00 app[api]: Deploy e1a7636b by user alexismastakouris08@gmail.com
2020-11-07T10:13:06.144839+00:00 app[api]: Release v18 created by user alexismastakouris08@gmail.com
2020-11-07T10:13:06.000000+00:00 app[api]: Build succeeded
2020-11-07T10:13:08.924332+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-07T10:13:11.837311+00:00 app[web.1]:
2020-11-07T10:13:11.837349+00:00 app[web.1]: > compass@1.0.0 start /app
2020-11-07T10:13:11.837349+00:00 app[web.1]: > node index.js
2020-11-07T10:13:11.837350+00:00 app[web.1]:
2020-11-07T10:13:12.713528+00:00 app[web.1]: This bot is online
2020-11-07T10:14:09.151016+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-11-07T10:14:09.171490+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-11-07T10:14:09.269376+00:00 heroku[web.1]: Process exited with status 137
2020-11-07T10:14:09.322850+00:00 heroku[web.1]: State changed from starting to crashed
【问题讨论】: