How can I uptime my discord bot on glitch

I’ve a problem uptiming my discord bot on glitch

EDIT: So it turns out that it is not allowed on Glitch to ping websites. So If you were using something like replit, then the instructions below are for you. However if you want it for free, replit needs payment.

But if you want to know how to do it, here is how:

Hello @Khalid_Reda! I have hosted many bots using uptimerobot.com. It is a free tool that simply pings your bot. Here is how it works:

In a new file, called keep_alive.py, insert this code:

from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def main():
  return "Your bot is alive!"

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

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

In your main.py or the main file, add these lines of code:

from keep_alive import keep_alive #Imports the keep_alive function from keep_alive.py
#All the bot code ASIDE from the Client.run() / Client.start
keep_alive()
#Now start your bot here

This will create a flask server. Get the glitch link, such as MyDiscordBot.glitch.me
In uptimerobot.com, create a new pinging bot, and then insert the link from the flask server.

If you have all the code properly made, you will get an output like this (very basic imitation:

Bot started
[TimeStamp] --- 0.0.0.0
[TimeStamp] --- 0.0.0.0
[TimeStamp] --- 0.0.0.0
Client running
[TimeStamp] --- 0.0.0.0
[TimeStamp] --- 0.0.0.0
[TimeStamp] --- 0.0.0.0
"Bot alive... or whatever your discord bot start message is"

I hope this helps!

P.S: Uptimerobot is a little unstable, sometimes the bot will be offline, but for the most part, it should stay up and running
P.P.S: if this helps, please mark it as the solution!

pinging projects is against glitch’s terms of service and will most likely get your project suspended. If you’re looking to keep your bot running 24/7, you should invest in glitch pro or find an alternative hosting service.

glitch rules aside, does this work? I heard that uptimerobot connections always get 403 or something and never wake up the proejct

I had it working for a long time before the url for Gizmo was removed.