How to solve a “429: Too Many Requests” when running discord.py bot on repl.it?

Other than avoiding the error, there’s a way to get around it. If discord.errors.HTTPException: 429 appears in the console on replit, just use the command kill 1 in the shell. This command completely exits the script, and when you click run again it will run from a different IP Address, bypassing the Discord rate limit.

If the error happens regularly, this can be a hassle. An automatic solution is to have another file called ‘restarter.py’ with this code:

from time import sleep
from os import system
sleep(7)
system("python main.py")

Then in your main script:

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
  print ('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return
  
  if message.content.startswith('$hello'):
    await message.channel.send('Hello!')

try:
    client.run(os.getenv('TOKEN'))
except discord.errors.HTTPException:
    print("\n\n\nBLOCKED BY RATE LIMITS\nRESTARTING NOW\n\n\n")
    system("python restarter.py")
    system('kill 1')

Leave a Comment