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
I've also tried
kord.rest.guild.getGuildMembers(...).toList()
which returns only me.have you enabled the intent in the developer portal too?
Yes, I have
The bot also has Administrator privileges
hm, anything suspicious in the logs? maybe with trace level enabled?
I only get code 200 responses back, no rate limits
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()
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/restDas 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
sure :)
but please keep your messages in english, so other people can understand too :)