Ask coding questions

← Back to all posts
Uptime Robot not working with Discord Cloudflare
h
xCloudzx (1)

Apparently Uptime Robot is sending invalid requests so my bot got temporarily banned from discord.com and I cannot run it anymore. Is there any alternative to Uptime Robot that will work with Discord?

Answered by c4syner (77) [earned 5 cycles]
View Answer
Commentshotnewtop
c4syner (77)

Try using my modified version of keep_alive, it doesn't require an external pinger.

from flask import Flask
from threading import Thread
import random
import time
import requests
import logging
app = Flask('')
@app.route('/')
def home():
    return "You have found the home of a Python program!"

def run():
  app.run(host='0.0.0.0',port=random.randint(2000,9000)) 
def ping(target, debug):
    while(True):
        r = requests.get(target)
        if(debug == True):
            print("Status Code: " + str(r.status_code))
        time.sleep(random.randint(180,300)) #alternate ping time between 3 and 5 minutes
def awake(target, debug=False):  
    log = logging.getLogger('werkzeug')
    log.disabled = True
    app.logger.disabled = True  
    t = Thread(target=run)
    r = Thread(target=ping, args=(target,debug,))
    t.start()
    r.start()

Then usage would look like:

import neverSleep
neverSleep.awake(yourReplURL, False)
#All your code: \/
c4syner (77)

@c4syner Oh and rename the top code to neverSleep.py. BTW I've had a discord bot staying alive for the past 2 months without issue with this!

xCloudzx (1)

@c4syner This looks promising! So I would put never sleep.awake at the top as opposed to right before bot.run?

c4syner (77)

@xCloudzx That's just what I did, you could put this where keep_alive is. (removing keep_alive of course)

G4RR3TTjonnyboi (0)

@c4syner Sorry I am just viewing this, I was wondering... Does it require Uptimerobot still? or is it just possible to have neversleep and no uptimerobot, idk thanks I know this was 5 months ago but just wondering...

c4syner (77)

@G4RR3TTjonnyboi It's been a while since I've used this but when I first built this, it didn't need any external programs. It kept itself alive by essentially pinging itself every few random minutes.

G4RR3TTjonnyboi (0)

@c4syner Thank you I know it has been a few months, It's just I have had the same problem and had to use this, Thanks and sorry for the trouble.

c4syner (77)

@G4RR3TTjonnyboi No trouble at all! If you need help getting it set up just ping me here.

Coder100 (12439)

Anyways, this has been happening to a lot of us recently with our bots going down and such. You can only keep up to 20 servers online at a time, however I feel like in your case, https://keeper-upper.turbio.repl.co and https://ping.matdoes.dev are good solutions.

xCloudzx (1)

@Coder100 I only have one bot on one server so that isn't a problem for me. Also those websites don't seem to be different from Uptime Robot's system so wouldn't it still break with them? Thanks for your help.

Coder100 (12439)

@xCloudzx hi, the thing is, repl.it right now is a bit unstable, so the best thing you can do is to have as many pinging services as possible

Coder100 (12439)

also, btw, keeper-upper is repl.it's official one @xCloudzx

Coder100 (12439)

your bot cannot be banned unless the code is malicious, not anything to do with requests.

xCloudzx (1)

My bot was temporarily banned. I think Discord considers what I did to be API Abuse. @Coder100

Coder100 (12439)

ohh no, that's a message overflow @xCloudzx

Coder100 (12439)

basically someone sent a lot of commands and made your bot spam, and reach the quota @xCloudzx

Coder100 (12439)

not a big deal, just make sure to add cooldown @xCloudzx

xCloudzx (1)

@Coder100 How would I do that? I've looked it up and found no answers. Is there any code I can look at?

Coder100 (12439)

Store it in a dict, something like this:

cooldown = {}

# set cooldown
cooldown["user_id"] = 10

# now just make it go down every 1 second

@xCloudzx

xCloudzx (1)

@Coder100 Wouldn't that only allow me to send one message every 10 seconds on the whole bot, not just one server? That's too slow. Is there any way to just get the amount of time I need to wait and do it only when I need to wait?

Coder100 (12439)

right now, it will set the cooldown for that user globally, because doing it in just one server will not help with your problem @xCloudzx

xCloudzx (1)

@Coder100 How do other bots handle this problem though? Because I'm sure not all of them have cooldowns.

Coder100 (12439)

unfortunately, you will need lower-level access to how the commands are executed to implement that @xCloudzx

Coder100 (12439)

basically, every time a user sends a message, it will be put into a waiting line (an array), and every 0.5 seconds that array gets executed and cleared. If the bot experiences an API rate limiting, the array gets cleared to prevent spam. @xCloudzx

xCloudzx (1)

@Coder100 This looks like a very nice solution, I will definitely try it. Thanks!

xCloudzx (1)

@Coder100 I see, but how does that break my bot? I understand not sending the message, but why was I not able to run my bot?