Search code examples
pythondiscord.pyreplituptime

How to get the replit link for uptime robot?


I have made a super simple discord bot (for study tracking sessions) and I want it to run 24/7

So from all the google searches, I found that I could do that with the help of uptime robot website and for that purpose I need the URL/link of my repl the format should be http://REPL-NAME--USERNAME.repl.co (I found somewhere)

But the problem is

I can't find the link/URL of my repl

My view of the repl window

any help would be appreciated (plz provide screenshots if possible) 🤗!!

i Tried to create my own URL like http://PythonStudyBotRepl--CodingCircle2.repl.co


Solution

  • You need to make the replit host a website.
    You can achieve this by making a webserver.py file.

    webserver.py

    from flask import Flask # Make sure to install the flask package
    from threading import Thread
    
    app = Flask('')
    
    @app.route('/') # The "main" page of the website. The root.
    def home():
      return "Webserver OK, Discord Bot OK"
    
    def run():
      app.run(host="0.0.0.0", port=8080)
    
    def keep_alive():
      t = Thread(target=run) # We use threading so the function doesn't block the discord client from running.
      t.start()
    
    # It's pretty simple, create a simple webserver using Flask so replit gives you a URL to use, when starting the webserver use threading so it doesn't block the rest of the code from running.
    

    To call it,
    main.py (or whatever the main file is called, bot.py, etc.)

    from webserver import keep_alive
    # [...]
    keep_alive()
    client.run(TOKEN)