Learn to Code via Tutorials on Repl.it!

← Back to all posts
Hosting your repl based discord.py bot on Heroku to keep it running INDEFINETLY for free!
johndo3 (21)

Hi Guys!

We have all seen @TheDrone7's tutorial on how to make a discord.py bot on repl.it (link to that here), but he did say "Repl it being just another host, won't be able to host it 24/7 so it will have a downtime of a few minutes within every 24 hours." Fortunately, I have a solution, HEROKU!


You must have an account for Discord, GitHub , Heroku, and Repl.it (you probably have an account already).

1. Create a bot and get its token

  • Create an application in the developer portal here
  • Open up your new application and click 'Add Bot' under the Bot settings to create your bot.
  • After creating the bot, click the 'Copy' button under the title Token. Take note of your token as you will need it later.

2. Create a new repository from this one

3. Set up Heroku

  • Create an application for Heroku here.
  • Under 'Deploy', do the following:
    • Deployment Method => Connect your GitHub
    • App connected to GitHub => Search for the forked repository
    • Automatic Deploy => Enable Automatic Deploy (to redeploy after every commit)
  • Under 'Settings', click on 'Reveal Config Vars' and enter the following:
    • VALUE => (Enter the bot token that you copied from the developer portal)
    • Click the 'Add' button after entering all of this information.
  • Under 'Resources', do the following:
    • Click on the 'Pencil' icon.
    • Switch the worker from off to on.
    • Click 'Confirm' to finalize the decision.
    • NOTE: You are given 550 free Dyno hours, which will not last the entire month. However, if you provide a credit card to verify your identity, you are given an additional 450 hours, which will allow your bot to run indefinitely. You will not be charged for this.

What's next?

  • Now you can tweak the main.py file as you please! just don't mess with the first 5 or last 2 lines (you can change the prefix in line 4 though.)
  • You can change the @app.route stiff in server.py
  • You can also change base.html and index.html without changing the stuff inside {% %} or {}, and you are able to change the css and js files freely
  • Don't change the rest of the files or the name of any file or folder unless you know what you're doing
  • Don't under any circumstances rename the "static" and "templates" folders

Original code belongs to audieni. I just made it more suitable for repl.it bot creators. Visit his repository here

I forked from his though IDK why it doesnt say

TheGaelicKing (1)

I don't understand why so many people dislike Heroku, I enjoy their services because it's much faster than repl and it's optimized for production. Sure, they have paid plans but don't all web hosts? The rates on the free plan are likely not going to be reached until you move on from a simple hobby project.

CodeLongAndPros (1624)

I'd rather have 5mins down than pay money.
Heroku is just another hosting provider, they can have downtime as well...

CodeLongAndPros (1624)

@johndo3 Still, I'm going to bet they have a premium service for 99.9999999% uptime.

johndo3 (21)

you wont need to pay for this


You can get hacker plan for free and then activate "always on" lol

johndo3 (21)

repl will put them to sleep after 1 [email protected]

CodeLongAndPros (1624)

@johndo3 Always-on is a thing, and uptime-robot and pinger.matdoes.dev

johndo3 (21)

Repl could potentially crash (very unlikely but could happen) so heroku can be a [email protected]

CodeLongAndPros (1624)

@johndo3 and repl and Heroku automagically sync?

CodingCactus (4367)

A bot going down for 2 minutes and being hosted on repl.it is much better than a bot being online forever but hosted on heroku in my opinion

johndo3 (21)

Heroku takes the code from repl so it is repl based @CodingCactus


Wont go to heroku, you have to give your real name just to evaluate some code

johndo3 (21)

just type in a dummy name, it works

Necrodragon41 (4)

@CodingCactus I prefer a thousand times hosting it on replit and having it go down for 20 seconds either to have it on heroku and have to deploy every time i make a single change