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.
background.py
from flask import Flask, request
from threading import Thread
app = Flask('')
@app.route('/')
def home():
return "I'm alive"
def run():
app.run(host='0.0.0.0', port=80)
def keep_alive():
t = Thread(target=run)
t.start()
main.py
from background import keep_alive
# bot commands
if __name__ == "__main__":
keep_alive()
# starting the bot
In this way, I ran the Flask application and the telegram bot in parallel.
2 Likes
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
2 Likes
Hi! Thanks for your reply! I use honeybadger.io to ping the flask app and it works perfectly, it’s like a always on repl!