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.memberCount doesn't update after refetch #997

Open
arslanarm opened this issue Jan 20, 2025 · 4 comments
Open

Guild.memberCount doesn't update after refetch #997

arslanarm opened this issue Jan 20, 2025 · 4 comments

Comments

@arslanarm
Copy link

Got the problem that member count is being null most of the time. The behavior that I got on a server with 700+ members:

  1. on the first iteration, memberCount is null
  2. on the second iteration, memberCount is set to actual one that is on the server.
  3. after entering voice chats and leaving from them, memberCount becomes null, and doesn't recover from that even after several minutes.

here is the code used.

@OptIn(PrivilegedIntent::class)
suspend fun main() {
    val kord = Kord(System.getenv("TOKEN"))
    val guildId = Snowflake(System.getenv("GUILD_ID"))

    kord.on<ReadyEvent> {
        val guild = kord.getGuild(guildId)
        coroutineScope {
            while (isActive) {
                val guildData = guild.fetchGuild()
                println("${guildData.memberCount} / ${guildData.voiceStates.filter { it.channelId != null }.count()}")
                delay(1000)
            }
        }
    }


    kord.login {
        intents += Intents(Intent.Guilds, Intent.GuildMembers, Intent.GuildVoiceStates)
    }
}

tried using rest supplier, but memberCount is always null. found out that by default withCounts in GuildService.getGuild is false, and there is no place to tweak it. Used GuildService directly via kord.rest.guild with withCounts = true, but the memberCount is Optional.Missing,

Then reverted back to using code above, and tested leaving and joining the server, to test how fast guild.memberCount is updated. Found out that after 5 minutes it still doesn't update.

Is there any workarounds to make it more "realtime"?

@DRSchlaubi
Copy link
Member

Could you set the log level to TRACE and check the result from Discord to see whether the memberCount is there

@arslanarm
Copy link
Author

Set log level to trace, tried using guild.withStrategy(EntitySupplierStrategy.rest).fetchGuild(), member_count is nowhere to be found in the response. I tried manually fetching using kord.rest.guild with withCounts = true and found out that the response contains approximate_member_count. I settled with using it, because it is the most recent member count that is available.

It is a bit unfortunate that I have to use kord.rest.guild to set withCounts and wrap it with Guild

@DRSchlaubi
Copy link
Member

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