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

Cache conflict when using Guilds and GuildMembers intents together #167

Closed
nlwillia opened this issue Jan 14, 2021 · 12 comments
Closed

Cache conflict when using Guilds and GuildMembers intents together #167

nlwillia opened this issue Jan 14, 2021 · 12 comments

Comments

@nlwillia
Copy link

I've attached a project that just connects and prints the member list from the ready event.

On the discord end, I've turned on the GUILD_MEMBERS flag.

I'm finding that if I configure Kord with just +Intent.GuildMember then I get all the members back from guild.members against my test server. But if I add +Intent.Guild it only returns the bot's own user.

	val kord = Kord(botToken) {
		intents {
			+Intent.Guilds // If uncommented then the full member list isn't seen
			+Intent.GuildMembers
		}
	}

It's weird to turn on an intent and get less data. The difference seems to be that Guild is causing the cache to be initialized prematurely. I'm wondering if that's supposed to happen or how I should work around it. This is kind of a one-off; I don't necessarily want the whole member list in cache, but if I ask for it, it's surprising if I don't get it. I guess I can use RestEntitySupplier directly...

@HopeBaron
Copy link
Member

Hello, What Kord version are you on?

@nlwillia
Copy link
Author

Sorry, 0.6.10

@HopeBaron
Copy link
Member

HopeBaron commented Jan 14, 2021

could you try using the snapshot on 0.7.x branch? There is a group id change as well so please read the readme there.
This is the PR updating the readme for 0.7.x
#159

@nlwillia
Copy link
Author

I couldn't get Gradle to resolve it before...looks like I didn't know about the extra repo.

With 0.7.x it doesn't matter how I configure the intents...guild.members always only sees the bot user instead of the full list, so it's more consistent but still suggests something unplanned happening w/the cache.

@DRSchlaubi
Copy link
Member

I couldn't get Gradle to resolve it before...looks like I didn't know about the extra repo.

you need to add the Sonatype repo: maven("https://oss.sonatype.org/content/repositories/snapshots")
then you can add the snapshot implementation("dev.kord:kord-core:0.7.0-SNAPSHOT")

@DRSchlaubi
Copy link
Member

DRSchlaubi commented Jan 14, 2021

Tried this

val kord = Kord(System.getenv("token")) {
        intents += Intents(Intent.Guilds, Intent.GuildMembers)
 }
                message.channel.createMessage(message.getGuild().members.toList().joinToString(" ") { it.displayName })

on the snapshot still only get the bot member

@HopeBaron
Copy link
Member

Hey, I'll look into it when possible, right now my Gradle isn't acting fine.
Will inform you of any updates. However if you'd like you can join our Discord server.

@DRSchlaubi
Copy link
Member

DRSchlaubi commented Jan 14, 2021

This works as a workaround:

kord.on<ReadyEvent> {
        for (guildId in guildIds) {
            gateway.requestGuildMembers(guildId).launchIn(kord)
        }
    }

@HopeBaron
Copy link
Member

HopeBaron commented Jan 14, 2021

Hello there, sorry for late replying but I have issues with my network here.
The issue here is that the cache is not yet filled with members.
in order to do this you call

gateway.requestGuildMembers(guildId) 

in your ReadyEvent.
this sends member chunks that we will cache for you
in order for the requests to be sent, you need to collect the result flows.

Now that you have the members of the guild you care about cached. you can list them in other events.

TL;DR:
if you want to have members of all guilds add this to your ReadyEvent

     for (guildId in guildIds) {
                gateway.requestGuildMembers(guildId).launchIn(kord)
            }

in-order to request and cache members through gateway.

@nlwillia
Copy link
Author

Okay. It sounds like this has evolved and there's a different approach now vs. the inconsistent and possibly unintended behavior in 0.6. I didn't start with 0.7 because it wasn't obvious from the front page how to setup the dependency, but I'll proceed with that and see how it goes. Member scanning is something I should probably handle differently anyway, but the weirdness with the intent config caught my attention and seemed like something that should be understood. Thanks for the attention.

@HopeBaron
Copy link
Member

You can view #55 for updates on the matters. Your question has sparked a discussion
And it seems better in your case to just use the GUILD_PRESENCE intent
which will provide us with the members in GuildCreateEvent, which in turn will allow us to cache them

If you are using Gateway Intents, members and presences returned in this event will only contain your bot and users in voice channels unless you specify the GUILD_PRESENCES intent.

look more into it here: https://discord.com/developers/docs/topics/gateway#guilds

@HopeBaron
Copy link
Member

The issue has been closed due to inactivity, feel free to open it again if you face further problems.

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