I’m working on a Discord bot that updates a voice channel name when players join or leave a Minecraft server. The bot is supposed to rename the channel every time there’s a change in player count. But I’m running into a weird issue.
Even though I’m sending way fewer requests than Discord’s limit of 50 per second, I’m still getting rate limited. I’ve tried setting a 20-second delay between requests, but I still hit the limit after just 3 renames.
Here’s a snippet of my code:
@tasks.loop(seconds=1)
async def rename_channel():
global player_count
try:
current_status = minecraft_server.get_status()
voice_ch = bot.get_channel(CHANNEL_ID)
if not voice_ch:
print('Channel not found')
return
if player_count != current_status.active_players:
await voice_ch.edit(name=f'Players: {current_status.active_players}')
print(f'Channel renamed: {current_status.active_players} players')
player_count = current_status.active_players
else:
print('No change')
except Exception as e:
print(f'Error: {e}')
@bot.event
async def on_startup():
print(f'Bot active: {bot.user}')
initial_players = minecraft_server.get_status().active_players
await bot.get_channel(CHANNEL_ID).edit(name=f'Players: {initial_players}')
print(f'Initial channel name set: {initial_players} players')
rename_channel.start()
The error I’m getting is:
discord.http We are being rate limited. PATCH *{Channel_ID_link}* responded with 429. Retrying in 580.74 seconds.
This happens after about 2-3 successful renames. Am I missing something in my code? Any ideas on how to fix this?