Harrison Copp
Harrison Copp

Reputation: 97

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 -

Upvotes: 7

Views: 40886

Answers (2)

openwld
openwld

Reputation: 1196

Although @Skidee's solution seems to work, there is a major issue. Repl.it uses shared IPs. And doing that will cause discord's cloudflare to throw a 429 too many requests. Thus, even though you are keeping the repl running using uptimerobot or buying the paid always-up repls, you will not be able to keep your bot online all the time.

Using a VPS is the ONLY solution to the problem. Plus, no good hosting is free. Use Amazon cloud if you are in the U.S. because it provides a 12-month trial.

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

This "error" message doesn't mean anything errored. On the contrary, it indicates your keep_alive functoin has started working.

Refer to Discord API cloudflare banning my repl.it repo if you want to know more.

Upvotes: 1

Skidee
Skidee

Reputation: 657

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!

Upvotes: 21

Related Questions