Repository navigation
Chunk servers when needed instead of all at startup - #210
Merged
Merged
Conversation
With the members intent, discord.py chunked every server at startup, which takes many minutes of gateway rate limits on every restart and holds back ready (and every background loop) until it's done. Guild sync, key role sync and EVTC autoposting already chunk a server before reading its members; forced account names and /guild members' mentions now do too. Without the startup chunk most users aren't cached, so event reminders, EVTC autoposts and guild sync authorization replies look users up with bot.get_or_fetch_user: the cache, or else Discord, fetched once and remembered. Before, they skipped anyone not cached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With the members intent on, discord.py requested the member list of every server at startup. Each shard can send only about 120 gateway messages a minute, so a restart meant many minutes of
WebSocket in shard ID N is ratelimitedwarnings. Ready, and with it every background loop, waited until all of it finished.Startup:
chunk_guilds_at_startup=False. The bot is ready as soon as it has connected.Code that reads a server's members chunks that server first. Guild sync, key role sync and EVTC autoposting already did. Two places didn't, and now do:
/guild members, which would lose its mentions of people on the server.Only servers using these features get chunked, as they're reached, rather than all of them up front.
User lookups: without the startup chunk, most users aren't cached. Three places used
bot.get_userwith no fallback, and quietly skipped anyone not cached:They now use the new
bot.get_or_fetch_user, which tries the cache, then fetches the user from Discord once and remembers them. That matters for reminders, whose loop runs every 10 seconds. The gem tracker and the owner DM already fell back to fetching.EVTC: an autopost for a user who deleted their Discord account is now skipped without logging an error.
Test plan
get_or_fetch_useruses the cache, fetches once, and returns None for unknown users;/guild memberschunks the server before mentioning members (failed before the fix).ruff checkclean.Ready, serving N guildswithin a minute or so of connecting; then check that event reminders, guild sync and forced names still run.🤖 Generated with Claude Code