Reputation: 97
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
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
Reputation: 657
To keep your repl.it bot online 24/7 you have to do 3 things :
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 :
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