Heroku托管的麻烦(discord bot)

时间:2020-04-08 00:03:07

标签: node.js heroku discord discord.js

Heroku不允许我启动该应用程序,因为它会停留几秒钟,然后发生这种情况:

2020-04-07T23:11:35.586817+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-07T23:11:35.597942+00:00 heroku[web.1]: State changed from crashed to starting

此后,Heroku重新启动应用程序,并且上面的代码又显示了一次(这次没有重新启动,只是崩溃)。

2020-04-07T23:12:38.593514+00:00 heroku[web.1]: State changed from starting to crashed

我已经在代码中搜索了问题,但找不到任何问题,因此删除了所有内容,并将主文件core.js设置为一个discord bot,它仅发送带有标题的嵌入消息:

const { Client, MessageEmbed } = require('discord.js')
const client = new Client()
let channel = null

client.on('ready', () => {
  console.log(`bot ${client.user.tag} running`)
  channel = client.channels.cache.find(ch => /generic_channel_name/.test(ch.name))

  const embed = new MessageEmbed()
    .setTitle('Commom title')
    .setColor('#ffff00');
    channel.send(embed)
})

client.login(config.token)

即使只有一个setInterval也会导致Heroku导致应用崩溃:

setInterval(() => {
  console.log('Testing')
}, 3000)

我确实尝试了很多事情,但是我没有失败的唯一事情就是从0到100.000的简单for循环

有人可以帮我吗?

3 个答案:

答案 0 :(得分:0)

发生这种情况的原因有很多,最常见的原因是:

1. You do not have a Procfile.
Solution for this: make a Procfile which just says `worker node core.js` or `worker node .`.
2. You do not have enabled node dyno from the Heroku site.
Solution for this: Head to Dynos and enable node.
3. You have not updated your package.json.
Solution for this: Head to console/terminal and then say `npm init` and fill whatever it asks you to fill, Make sure that dependencies are properly aligned.

很抱歉,如果这样做不能帮助您。

答案 1 :(得分:0)

查看您的日志,启动和崩溃之间有60秒的差异,这可能意味着您的应用达到了Heroku运行时60秒的Dyno启动超时(https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout)。如果发生这种情况,您还应该在日志流中看到R10错误。 Dynos无法启动的原因有很多,但最有可能的原因通常是您的服务器未正确绑定$PORT环境变量,这意味着Heroku Routers无法确定您的应用程序是否正在运行。

答案 2 :(得分:0)

我发现了问题。我的Procfile的内容为web: node example/path,所以我只是将其更改为worker: node example/path,删除了我的Heroku的应用程序,重新创建了它,然后再试一次。我还确保在Heroku的“资源”选项卡中,停用了“网络”选项,并激活了“工作人员”选项。 Heroku的这一步骤加上一个单词更改(从 web 更改为 worker ),一切都变了,现在一切正常。

感谢您的时间和答案