I know that hosting a discord bot with Repl.it isn't very conventional. I've gotten multiple remarks about hosting it there. But I didn't really have any alternative ways of hosting a bot there.
However, hosting a python discord bot with repl.it was quite hard. I had scraped the internet for quite some time before finding a solution.
I just had to make a keep alive script and use Uptime Robot.
The keep alive script is very simple and isn't very long. You just need to include flask in requirements.txt and use threads.
from flask import Flask from threading import Thread app = Flask('') @app.route('/') def home(): return "Bot is online" def run(): app.run(host='0.0.0.0',port=8080) def keep_alive(): t = Thread(target=run) t.start()
Then on your main python file, import the
keep_alive() function. Then, right before you run your bot, include
This code, in summary, makes a website that just says "Bot is online"
However, repl.it doesn't keep this code on 24/7. You need to make a GET request to this site every so often for it to run constantly. This is where Uptime Robot comes in.
Go to https://uptimerobot.com and sign up with a free plan. Then create a monitor by clicking the button.
monitor type, put Http(s). Put whatever unique name you want in
Friendly Name. For
URL (or IP) you want to put the URL that the flask shows up on. Once you run the discord bot on repl, a box appears on the top-right of the interface with the URL.
That's it! It's done. Just click run on repl.it and you can close the tab. It works!
If you have any questions, let me know :D