Hosting your repl based discord.py bot on Heroku to keep it running INDEFINETLY for free!
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
- Create a new repository from this one here. Follow all the prompts and hit "Create repository from template" This contains all the code you need to host your bot on Heroku. You can also view the repository here
- Open a new tab and put in this link: https://repl.it/github/YOUR_GITHUB_USERNAME_HERE/YOUR_REPO_NAME_HERE
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
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.
Just use uptimerobot?
@XdekHaker doesn't work anymore as expected - there's some downtime still even if you ping it every 5 min
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.
I'd rather have 5mins down than pay money.
Heroku is just another hosting provider, they can have downtime as well...
it won't charge you @CodeLongAndPros
@johndo3 Still, I'm going to bet they have a premium service for 99.9999999% uptime.
@johndo3 They still charge https://www.heroku.com/pricing
you wont need to pay for this
@CodeLongAndPros
You can get hacker plan for free and then activate "always on" lol
repl will put them to sleep after 1 [email protected]
@johndo3 Always-on is a thing, and uptime-robot and pinger.matdoes.dev
Repl could potentially crash (very unlikely but could happen) so heroku can be a [email protected]
also getting a lot of criticism :( @CodeLongAndPros @CodingCactus @behavingEffort
@johndo3 and repl and Heroku automagically sync?
through github yes @CodeLongAndPros
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
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
just type in a dummy name, it works
@behavingEffort
@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
i didnt see any pencil button in the resources tab