Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep Discord Bot online on repl.it

How do I use repl.it for my Python Discord Bot, and keep it running 24/7. I used to use keep_alive but it stops working for some reason.

Does anyone have any suggestions?

I keep getting this error in the console:

172.18.0.1 - - [16/Feb/2019 11:25:10] "GET / HTTP/1.1" 200 -

like image 958
Harrison Copp Avatar asked Jan 01 '23 07:01

Harrison Copp


1 Answers

To keep your repl.it bot online 24/7 you have to do 3 things :

  1. keeping the bot alive
  2. adding a background task
  3. 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 (preview)
  • select monitor type Http(s) (preview)
  • 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 (preview)
  • 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 (preview)
  • 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!

like image 62
Skidee Avatar answered Jan 13 '23 00:01

Skidee