【问题标题】:Troubles with Heroku hosting (discord bot)Heroku 托管问题(不和谐机器人)
【发布时间】:2020-07-20 07:30:11
【问题描述】:

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重启应用,上面的代码又显示了一次(这次没有重启,只是crash)。

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

我已经在我的代码中搜索了问题,但我找不到任何问题,所以我删除了所有内容,并将我的主文件 core.js 设为一个不和谐机器人,它只发送带有标题的嵌入消息:

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 循环

有人可以帮我吗?

【问题讨论】:

    标签: node.js heroku discord discord.js


    【解决方案1】:

    我发现了问题。我的 Procfile 的内容是web: node example/path,所以我只是将其更改为worker: node example/path,删除了我的 Heroku 应用程序,重新创建并再次尝试。我还确保在 Heroku 的“资源”选项卡中,“web”选项被禁用,“worker”选项被激活。这个 Heroku 的步骤加上一个词的变化(webworker)改变了一切,现在一切正常。

    感谢您的宝贵时间和回答

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        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.
        

        抱歉,如果这对您没有帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-10-25
          • 2022-11-10
          • 2021-01-25
          • 2021-03-04
          • 2021-12-13
          • 2019-09-09
          • 2019-02-26
          • 1970-01-01
          相关资源
          最近更新 更多