1

I'm trying to make a discord bot that runs 24/7 using Heroku. Everything is good, except for the fact that the bot crashes after 60 seconds.

The error output tells me this:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

I looked for solutions on the internet, and I found quite a few. However, none of them worked.

Here's my main file's code:

const Discord = require('discord.js')
const {prefix, token} = require('./config.json')
const client = new Discord.Client()

// Login
client.login(token)

client.once('ready', () => {
    console.log('Back online')
    client.user.setActivity(' channel', {type: 'LISTENING'})
})

client.on('message', message => {
    if (message.author.bot) {
        return;
    }

    if (message.content.toLowerCase() === 'hello') {
        message.channel.send('Hey!')
    }
})
xcdev
  • 37
  • 5
  • Does this answer your question? [Heroku Node.js Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch](https://stackoverflow.com/questions/31092538/heroku-node-js-error-r10-boot-timeout-web-process-failed-to-bind-to-port-w) – Jakye Feb 15 '20 at 09:24
  • Yes, this post did help. Thanks :) – xcdev Feb 15 '20 at 13:49

1 Answers1

2

You've most likely assigned your bot to run on a web service in your Procfile. The Heroku Procfile is a file that stores information about what processes Heroku should run. If you set your Procfile to run a web service, Heroku expects you to bind to the required port (using process.env.PORT) once it launched. If it didn't then Heroku will assume that your program failed to start and will restart it.

As of now, your Procfile most likely looks like this:

web: node index.js

This tells Heroku to run your program in a web dyno. However, if you don't bind to an HTTP port with a Node.js service like Express, Heroku will crash your program. To fix this, change web to worker.

worker: node index.js

Note that by changing your Procfile to use worker, your free dyno hours (if you are running on a free dyno) will continue decreasing 24/7, and you'll be using up around 700 hours per month. If you registered your credit card, the limit is set to 1000 hours per month and you don't have to worry. Otherwise, you have to upgrade your dyno to a Hobby dyno to keep your bot running the entire month.

EDIT: Though this wasn't the accepted answer, I still have to clarify that sometimes Heroku doesn't read the Procfile settings. In that case, you should run these commands in the folder where your project is:

heroku ps:scale web=0
heroku ps:scale worker=1

This will force Heroku to use the worker dyno defined in your Procfile. Hope this helps.

Chlod Alejandro
  • 566
  • 8
  • 16