kordlib/kord

How to get all members in guild and all members in role?

Closed this issue · 4 comments

Hello, I tried use this code

interaction.guild.members.collect {
            println(it.username)
}

But it show me my bot and active persons in voice chat:

sobakevich
covid272
gigaser
.ivano
ATroll Bot

image
I don't understand how its working, please help me. Thank you for a lib
Best regards, Sergey

Hello @GigaSer,

Regarding guild.members, it retrieves all the members from the cache and fetches the rest from the API if any are not found. (docs).

To determine the total number of members, it's possible that the current count represents only the cached members. If you want to fetch all members from both the cache and the API, you can use guild.withStrategy(EntitySupplyStrategy.cachingRest).members and observe if this provides the expected output.

Keep in mind that withStrategy returns a new guild instance that uses the provided strategy by default. The default behavior is to first check the cache for data, and if there are no matches, it falls back to making a request to the API.

I hope this helps! Let me know if you have any further questions.

Thank you very much for the answer. Do I understand correctly, that there is only way to get all members in role is filter all members in guild?

@GigaSer, No.
You may just call members without filtering
The filtering in the doc is just an example to show that you can use it.

Thank you, it's working! You are the best