Skip to content
← Back to Community
Hosting your repl based discord.py bot on Heroku to keep it running INDEFINETLY for free!
Profile icon
johndo3

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!

Prerequisites

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:
    • KEY => DISCORD_TOKEN
    • 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

Voters
Profile icon
ethanwlol000
Profile icon
abhisekp
Profile icon
bc78
Profile icon
kkhcheng
Profile icon
LoneVigil
Profile icon
johndo3
Comments
hotnewtop
Profile icon
akashkroos

i didnt see any pencil button in the resources tab

Profile icon
TheGaelicKing

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.

Profile icon
johndo3
Profile icon
XdekHaker

Just use uptimerobot?

Profile icon
orliesaurus

@XdekHaker doesn't work anymore as expected - there's some downtime still even if you ping it every 5 min

Profile icon
polsoda

My goal is to set up my bot with a private repo, but if it's based on replit, it's gonna be public.
Also, my bot uses replit's database, when I updated your code with my functionality (using replit's db), the bot remains offline (I'm guessing that's the issue).
Should I change the database? What could I use instead of replit's database that works on Heroku? I plan to delete the bot from replit once it's working.

Profile icon
johndo3

@polsoda it doesnt matter if it's public, no one will search it up

Profile icon
CodeLongAndPros

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

Profile icon
johndo3

it won't charge you @CodeLongAndPros

Profile icon
CodeLongAndPros

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

Profile icon
johndo3
Profile icon
CodeLongAndPros
Profile icon
johndo3

you wont need to pay for this
@CodeLongAndPros

Profile icon
[deleted]

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

Profile icon
johndo3

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

Profile icon
CodeLongAndPros

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

Profile icon
johndo3

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

Profile icon
johndo3

also getting a lot of criticism :( @CodeLongAndPros @CodingCactus @behavingEffort

Profile icon
CodeLongAndPros

@johndo3 and repl and Heroku automagically sync?

Profile icon
johndo3

through github yes @CodeLongAndPros

Profile icon
CrazyVideoGamer
Profile icon
CodingCactus

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

Profile icon
johndo3

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

Profile icon
[deleted]

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

Profile icon
johndo3

just type in a dummy name, it works
@behavingEffort

Profile icon
Necrodragon41

@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