K
Kord3w ago
blur

Can't get guild members

Hello, Inside a Guild Chat Input Command, I have this code: interaction.guild.members.toList() This returns only the bot. Intents are enabled. Server only has 4 members. I'd appreciate any help.
11 Replies
blur
blur3w ago
I've also tried kord.rest.guild.getGuildMembers(...).toList() which returns only me.
LustigerLurch
LustigerLurch3w ago
have you enabled the intent in the developer portal too?
blur
blur3w ago
Yes, I have The bot also has Administrator privileges
blur
blur3w ago
No description
No description
LustigerLurch
LustigerLurch3w ago
hm, anything suspicious in the logs? maybe with trace level enabled?
blur
blur3w ago
I only get code 200 responses back, no rate limits
blur
blur3w ago
Solved the issue. The bug was that the internal member cache does not auto-populate on bot startup, and only adds a new member once they have interacted in the server. Inside the main class (not in a command), I can retrieve all members using kord.getGuild(Snowflake(GUILD_ID)).members. I store that state then in my own global members variable, updating accordingly. Inside a command, that code only returns the bot itself. Also, why do all of these behave differently and why are there so many? kord.getGuild(Snowflake(GUILD_ID)).members kord.rest.guild.getGuildMembers(Snowflake(GUILD_ID)) kord.rest.guild.getGuild(Snowflake(GUILD_ID)).members interaction.guild.members interaction.getGuild().members interaction.guild.requestMembers() interaction.getGuild().requestMembers()
LustigerLurch
LustigerLurch3w ago
i was suspecting a cache thing to be the issue, but the fact that you tried using a direct rest call didn't support that suspicion - kord.getGuild(id).members is in the kord-core module and uses GuildBehavior.members: this gets the members based on the configured EntitySupplier (cache or rest or some combination, see EntitySuppplyStrategy), cache is only implemented in the kord-core module - kord.rest.guild.getGuildMembers uses GuildService.getGuildMembers in the kord-rest module: this is only a thin wrapper around the raw http api call - kord.rest.guild.getGuild(id).members: again a thin wrapper around this - the members property of DiscordGuild will not be present when using GuildService.getGuild, it's only present when received via gateway - we should probably split DiscordGuild for this difference between rest and the guild create gateway event - interaction.guild.members and interaction.getGuild().members also use GuildBehavior.members, the difference is that interaction.guild doesn't do any request or cache lookup to get the guild - it only provides a handle (GuildBehavior) but not any data about the guild - interaction.getGuild does a request/cache lookup to return a full Guild object - interaction.guild.requestMembers() and interaction.getGuild().requestMembers(): same as above for the difference between guild/getGuild; however GuildBehavior.requestMembers gives access to the Request Guild Members gateway send event instead of using cache/rest
blur
blur3w ago
Das sind sehr viele Informationen zum Verdauen und ehrlich gesagt verstehe ich nur die Hälfte, aber dennoch danke, dass du dir die Zeit genommen hast für diese ausführliche Erklärung. Discords API ist wirklich gigantisch
LustigerLurch
LustigerLurch3w ago
sure :) but please keep your messages in english, so other people can understand too :)
Want results from more Discord servers?
Add your server