To keep your repl.it bot online 24/7 you have to do 3 things :
- keeping the bot alive
- adding a background task
- link your repl.it bot with uptime robot
1. To keep our bot alive we have to add the following code on the head of our py file:
from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def main():
return "Your Bot Is Ready"
def run():
app.run(host="0.0.0.0", port=8000)
def keep_alive():
server = Thread(target=run)
server.start()
2. Adding a background task :
status = cycle(['with Python','JetHub'])
@bot.event
async def on_ready():
change_status.start()
print("Your bot is ready")
@tasks.loop(seconds=10)
async def change_status():
await bot.change_presence(activity=discord.Game(next(status)))
3. Setup the Uptime Robot :
- Create an account on uptime robot.
- After creating an account, go to the dashboard and click on Add new monitor

- select monitor type Http(s)

- then go to to ur project on repl.it and copy the url from the top of the console and paste it in url section of the monitor

- now set the monitoring interval to every 5 mins (so that it will ping the bot every 5 mins) and click on create monitor twice

- That’s it… Now go to ur project on repl.it and hit the Run button
If you have made your discord bot in discord.js, I wrote a medium article on that : Host a Discord Bot 24/7 Online for FREE!