Skip to content

Commit d648230

Browse files
rootclaude
authored andcommitted
Fix Discord rate limiting issues and update discord.py version
- Update discord.py to >=2.5.0 for latest features and fixes - Add RateLimited exception handling to dashboard message edits - Implement retry logic with exponential backoff for command tree sync - Add proper error logging for rate limit scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 58dc101 commit d648230

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

cogs/jellyfin_core.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,17 @@ async def _update_dashboard_message(self, channel: discord.TextChannel, embed: d
705705
message = await channel.fetch_message(self.dashboard_message_id)
706706
await message.edit(embed=embed)
707707
return
708+
except discord.RateLimited as e:
709+
self.logger.warning(f"Rate limited, waiting {e.retry_after} seconds")
710+
await asyncio.sleep(e.retry_after)
711+
# Retry once
712+
try:
713+
message = await channel.fetch_message(self.dashboard_message_id)
714+
await message.edit(embed=embed)
715+
return
716+
except Exception as retry_e:
717+
self.logger.error(f"Failed to edit message after rate limit: {retry_e}")
718+
return
708719
except discord.NotFound:
709720
self.dashboard_message_id = None
710721
except discord.Forbidden:

main.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,28 @@ async def load_cogs() -> None:
6666
except commands.ExtensionError as e:
6767
bot_logger.error(f"Failed to load cog {filename[:-3]}: {e}")
6868

69+
async def sync_with_retry() -> None:
70+
"""Sync command tree with exponential backoff retry logic."""
71+
for attempt in range(3):
72+
try:
73+
await tree.sync()
74+
bot_logger.info("Command tree synced")
75+
return
76+
except discord.RateLimited as e:
77+
bot_logger.warning(f"Rate limited during sync, waiting {e.retry_after}s (attempt {attempt + 1}/3)")
78+
await asyncio.sleep(e.retry_after)
79+
except discord.HTTPException as e:
80+
bot_logger.error(f"Failed to sync command tree (attempt {attempt + 1}/3): {e}")
81+
if attempt < 2:
82+
await asyncio.sleep(2 ** attempt)
83+
bot_logger.error("Failed to sync command tree after 3 attempts")
84+
6985
@bot.event
7086
async def on_ready() -> None:
7187
"""Handle bot startup: log readiness, load cogs, and sync command tree."""
7288
bot_logger.info(f"Bot is online as {bot.user.name}")
7389
await load_cogs()
74-
try:
75-
await tree.sync()
76-
bot_logger.info("Command tree synced")
77-
except discord.HTTPException as e:
78-
bot_logger.error(f"Failed to sync command tree: {e}")
90+
await sync_with_retry()
7991

8092
@tree.command(name="load", description="Load a specific cog")
8193
async def load(interaction: discord.Interaction, cog: str) -> None:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
discord.py
1+
discord.py>=2.5.0
22
jellyfin-api-client
33
requests
44
aiohttp

0 commit comments

Comments
 (0)