#chunk_guilds_at_startup workaround

1 messages · Page 1 of 1 (latest)

kindred frost
#

I set chunk_guilds_at_startup=False in my Bot but now i still want to access the users.
so my idea would be a task that fetches every n minutes guilds like this? is this the way to go or are there better ways?

chunked_guilds = set()

@tasks.loop(minutes=10)
async def fetch_members_task(self):
  """Periodically fetch members for guilds that haven't been chunked yet"""

  for guild in self.bot.guilds:
    if guild.id not in chunked_guilds and not guild.chunked:
      try:
        await guild.chunk()
        chunked_guilds.add(guild.id)
        await asyncio.sleep(2)  # Add delay between requests to avoid rate limits
      except Exception as e:
        pass
round marlin
#

Also I think chuck it once is enough since then it will be cached and so update by itself

quiet quail
#

why are you disabling it

kindred frost
#

the on_ready takes so long, and till that you cant use buttons as far as i know

quiet quail
#

is your bot in over 100 servers?

kindred frost
#

yes

quiet quail
#

rip

kindred frost
#

600 and 600k users about if that matters

#

so maybe an on_ready() function which iterates over every bot.guilds and do guild.chunk() ? @round marlin

jolly canyon
#

you can just add a check to your commands, check whether Guild.chunked is False, if so, call Guild.chunk

#

and done, you'll have the members cached just if they use any command

kindred frost
jolly canyon
#

?

kindred frost
#

bot.fetch_user() doesnt "update" the mutual_guilds parameter afaik

jolly canyon
#

You should not use fetch_user

round marlin
#

Less than 5min

jolly canyon
kindred frost
round marlin
kindred frost
#

no just for changes

round marlin
kindred frost
#

yeah i guess, what for is that chunk option then?

round marlin
#

Just guild check at startup mode True

kindred frost
#

wdym?

kindred frost
#

oh yeah i thought you meant something esle 👍

hexed flint
balmy star
#

well on_ready blocks everything, that's why buttons don't work

#

chunking is done through the gateway so chunk at startup halts on_ready to complete it

#

theoretically you could create a separate thread or something to chunk in the background, but i don't think that's something we'd officially implement and you'll need to adjust your bot with the possibility of missing members in mind (e.g. block if guild.chunked is false)

wild umbra
balmy star
#

basically 2 parts

  1. the gateway itself when sending chunks means other events are queued after; they attempted an adjustment, but it was reverted
  2. the library assumes the first behaviour and so waits for all chunks first; even if we did try to chunk in background the bot wouldn't receive events well