Created
December 10, 2020 15:42
-
-
Save beaucarnes/51ec37412ab181a2e3fd320ee474b671 to your computer and use it in GitHub Desktop.
Python Server for Discord Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
I hate replit soo much, this problem still hasn't been fixed yet.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
being rate-limited in replit isn't rare at all, when someone possibly creates a malicious bot and spammed discord until death
if that happens, you can make a simple try catch in the last line:
from subprocess import run
try: client.run(os.environ['TOKEN']) except: run(['kill', '1'])
(it only checks the api in start-up, it doesn't work if the bot died halfway)
or, you can make another thread that checks every 300-600 seconds if connecting to discord api (https://discord.com/api/v9/) returns 429 using urllib and threading, but i'm too lazy for that :p