2

I host my bot on replit, for the past week my bot is getting rate limited pretty often. In replit we fix rate limits by using kill 1 in shell. So I want my bot to automatically execute kill 1 every time it gets rate limited.

I've already tried this:

client = commands.Bot(command_prefix='!')

try:
  @client.event
  async def on_message(message):
    
      if message.author == client.user:
          return
      
      if "give me admin" in message.content:
          role = get(message.guild.roles, name='Admin')
          await message.author.add_roles(role)

      if 'yeet' in message.content:
          print('YEETT')

except:
  print("kill 1")
  subprocess.call("kill 1", shell=True)

I'm new to python so idk if I'm using try/except command at the right place

1 Answers1

0

try / except will attempt to run the try block and if it fails, it will look for an except block with the correct exception type (since you used except without a type, it will run on any exception. This is discouraged by the way, as it makes debugging harder).

To quote the Discord docs on rate limits:

In the case that a rate limit is exceeded, the API will return a HTTP 429 response code with a JSON body.

This means that a rate limit will still give you a valid response, triggering the try block. You would have to check the HTTP response code instead to find whether you exceeded your rate limit.

I would discourage doing this in general however, since trying to circumvent the rate limits may get your discord developer account suspended.

felix
  • 109
  • 1
  • 6
  • ty for answering. I'm a noob, so can you pls link me to an article or answer which shows how to get HTTP response code from discord API? – John Persuro Jan 25 '22 at 09:16