Home > database >  discord.py bot running flask wen server continuously going down
discord.py bot running flask wen server continuously going down

Time:03-24

I have set up my bot using discord.py and have it running a flask web server to keep it online. I also have the bot setup with UptimeRobot to constantly ping the bot so it will stay online. The bot was working completely fine and running consistently until discord's latest crash about a week ago. Since then, it had been going down nonstop, usually 3 to 4 times a day, and not telling me why in the console. My other confusing area is I have several versions of this same bot, but only one of them is having this issue. I know the question is quite broad, but had anyone else had this same issue? And if so, have you found any solutions? Its getting quite annoying and causing a lot of server problems and I have tried many different things (creating a new monitor on uptime robot, resetting the boy key, refreshing the bots code) and none of these solutions have worked for more than one day. Thanks for any words in advance :).

from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def home():
        return "Bot is running"
def run():
        app.run(host='0.0.0.0', port=8080)
def keep_alive():
        t = Thread(target=run)
        t.start()

Above is my code which runs the web server. I can see in the console that this is getting pings from uptime robot, when active (and when the bot goes down sometimes the web server is still running, so it will continue to get pings but the bot itself will not run). Bascially this thing has just been super inconsistent ever since discord's latest crash, and I haven't changed anything with the bots code or how it runs, other than the bot's token, all of which, have been to no avail.

CodePudding user response:

I use uptimerobot too... I dont have problems with it. This is my code.

from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def home():
    return "Hello. I am alive!"

def run():
  app.run(host='0.0.0.0',port=8080)

def keep_alive():
    t = Thread(target=run)
    t.start()

Closely the same, only i have spaces in between. make sure you have everything the correct way setup in Uptimerobot itself. I see you use the ping function of uptimerobot. I use HTML, maybe thats the big difference. To get the HTML link watch this video: https://www.youtube.com/watch?v=SPTfmiYiuok and go to 1:03:48!

CodePudding user response:

I have the exact same code, it stopped working these past few days. used to be able to run weeks without any problems

  • Related