Is it possible to run a flask app while running a discord bot?

is it possible to use a flask app ( to keep alive ) and run a discord bot at the same time? I am having issues with running this, can yall give me an example of how to do this?

To do this, you will have to resort to the threading module.

from flask import Flask, request
from threading import Thread

app = Flask('')

def home():
  return "I'm alive"

def run():'', port=80)

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

from background import keep_alive

# bot commands

if __name__ == "__main__":
    # starting the bot

In this way, I ran the Flask application and the telegram bot in parallel.


It won’t stay alive if the keep alive is in the same Repl.

How else would it work then? Or do you mean that it can’t be pinged by itself?

1 Like

Technically it will ping itself but it’ll just be force shut from replit


Hi! Thanks for your reply! I use to ping the flask app and it works perfectly, it’s like a always on repl!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.