Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guild members not available in GuildCreateEvent #945

Closed
Galarzaa90 opened this issue May 29, 2024 · 5 comments
Closed

Guild members not available in GuildCreateEvent #945

Galarzaa90 opened this issue May 29, 2024 · 5 comments

Comments

@Galarzaa90
Copy link
Contributor

The Guild Create event in Discord provides additional data besides the data usually found on guild objects. Among this data is the members property.

This property is useful to know if a guild is "chunked" or not (by comparing memberCount with the size of members you can know if the guild has all members populated or not). This way you can request members only for the guilds that actually needed, saving you a lot of requests in bots (mine is in 15k servers).

The issue is that there is no way to access this member list in the event. Guild.members is a flow, and relies on cache, besides usually throwing ConcurrentModificationException just by trying to count its values. I'm currently doing it based on isLarge property, which should be good enough, but having members available could potentially save even more requests due to large guilds that happen to bring the entire member list due to meeting the other conditions.

By looking at the code, I believe this is probably not easy, and might need to introduce a Guild subclass to be used for this event?.

@DRSchlaubi
Copy link
Member

DRSchlaubi commented May 29, 2024

You can access the members field using the gateway API, however when using kord-core this chunking should be done by the cache, maybe it's worth reopening #55

kord.gateway.events.filterIsInstance<GuildCreate>.collect { event ->
  event.guild.members.value
}

@Galarzaa90
Copy link
Contributor Author

I am using kord-extensions (but created the issue here because the types are Kord's types)

And yes, exactly what I'm trying to do is:

  1. Request members only if the GuildCreate event does not contain them all, otherwise I just let the cache handle it.
  2. Trigger a custom event GuildChunkingReadyEvent that is fired when all guilds are chunked.

@DRSchlaubi
Copy link
Member

I am using kord-extensions (but created the issue here because the types are Kord's types)

You were right in doing that

I am not sure why #55 got closed (@lukellmann do you know why?) however what you're describing is exactly what the cache should already do automatically (if you specified the right intent), is there a reason why the current cache behavior doesn't work for you?

@lukellmann
Copy link
Member

I am not sure why #55 got closed (@lukellmann do you know why?)

sorry, i don't 😅

@DRSchlaubi
Copy link
Member

Closing this due to inactivity, feel free to reopen; most of this should be covered by #55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants