Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Guild.memberCount doesn't update after refetch #997

@arslanarm

Description

@arslanarm

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"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions