pythondiscorddiscord.py

Discord rate limiting while only sending 1 request per minute


I wanted to display the amount of people that are online on my minecraft server by naming a closed voice channel the amount of people online. I initially wanted to check every 60 seconds and update the voice channel if something has changed. I got the program up and running pretty quickly with discord.py but then it pretty quickly gave me the error message

WARNING discord.http We are being rate limited. PATCH https://discord.com/api/v10/channels/*** responded with 429.

It consistently gives me this error after I send my 5th request. I don't know if this is because you can only update the name of a voice channel 5 times per 600 seconds or if I am doing something wrong. Here is my code:

client = discord.Client(intents=discord.Intents.default())


@client.event
async def on_ready():
    channel = client.get_channel(int(CHANNEL_ID))
    update_info.start(channel)


@tasks.loop(seconds=60)
async def update_info(channel):
    global LastUpdate
    players_online = get_info(HOST, PORT)['players']['online']
    if players_online != LastUpdate:
        print("updating")
        await channel.edit(name=f"Users Online:  {players_online}")
        LastUpdate = players_online

client.run(BOT_TOKEN)

Any help is really appreciated


Solution

  • For some reason discord rate limits channel updates to 2 every 10 minutes as is pointed out in this queastion. How often can I rename discord channel's name? I even tried using the raw api endpoints and got the same result. So unfortunately there is no way around this problem.