首页 > 解决方案 > 在 Heroku 上部署 node.js 应用程序(discord.jd bot)导致错误

问题描述

我正在尝试在 heroku 上部署一个不和谐的机器人。它工作大约 1-2 分钟,然后出现错误

2020-08-10T10:05:17.228802+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-10T10:05:17.246146+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-10T10:05:17.307500+00:00 heroku[web.1]: Process exited with status 137
2020-08-10T10:05:17.347445+00:00 heroku[web.1]: State changed from starting to crashed

(完整日志):

2020-08-10T10:04:19.372794+00:00 app[web.1]: 
2020-08-10T10:04:19.372804+00:00 app[web.1]: > arepee-bot@1.0.0 start /app
2020-08-10T10:04:19.372804+00:00 app[web.1]: > node index.js
2020-08-10T10:04:19.372804+00:00 app[web.1]: 
2020-08-10T10:04:20.468443+00:00 app[web.1]: Bot [welcomeMessage.js] is ready!
2020-08-10T10:04:30.643838+00:00 app[web.1]: Bot [index.js] is ready!
2020-08-10T10:05:17.228802+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-10T10:05:17.246146+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-10T10:05:17.307500+00:00 heroku[web.1]: Process exited with status 137
2020-08-10T10:05:17.347445+00:00 heroku[web.1]: State changed from starting to crashed

中的start命令package.json是:node index.js

Procfile 是:

worker: node index.js

并且index.js是:

const Discord = require("discord.js")
const client = new Discord.Client()
const welcomeMessage = require("./welcomeMessage")

client.on("ready", () => {
    console.log("Bot [index.js] is ready!")
})

client.login(process.env.TOKEN)

我还有另一个文件welcomeMessage

const Discord = require("discord.js")
const client = new Discord.Client()

client.on("ready", () => {
    console.log("Bot [welcomeMessage.js] is ready!")
})

client.on('guildMemberAdd', member => {

    let welcomeChannel = client.channels.cache.get('0000000000000')

    welcomeChannel.send("hello world")
})

client.login(process.env.TOKEN)

是什么导致了这个问题?谢谢

标签: node.jsherokudiscord.js

解决方案


伙计,不知何故我在这里做了,第一次随机尝试对我有用,我很高兴!看,我希望它也对你有用。首先,去看看你的“ package.json”文件,里面你必须有:

"scripts": {
    
  },

你应该把“ start" : "node index.js”放在那里(即使'scripts'里面已经有其他东西了,但不要删除其他东西,只需添加这个)它会是这样的:

 "scripts": {
    "start": "node index.js",
  },

然后转到您的 Procfile 并将“”更改为worker : node index.jsworker npm start”(我尝试过,因为我注意到只有 web 工作并且它的命令是“web npm start”)

它应该可以解决问题!

我很确定这是为我解决的问题,现在它正在不停地运行,但如果不是解决的问题,我还在终端上使用了一些命令,命令:“ heroku run worker”,还有“ heroku ps:scale worker=1”。

我希望它会对你有所帮助,我连续 8 小时试图让它工作,因为我有其他错误,而且我知道这东西不起作用有多烦人。

Obs.:你还需要按照其他人之前所说的去做:

“(...)您需要禁用网络测功机并启用工作人员测功机”。

PS.:我知道你已经做了开始的事情,我只是想如果有人在没有这些信息的情况下到达这里,也许它会有所帮助。


推荐阅读