bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.12k stars 817 forks source link

[?Bug] Doubling guild members #639

Open ghost opened 5 years ago

ghost commented 5 years ago

In the state i have doubling some guild members. Now, I use a little util function for fix it (below).

func UniqueMembers(members []*discordgo.Member) []*discordgo.Member {
    var unique []*discordgo.Member
    mm := make(map[string]*discordgo.Member)
    for _, member := range members {
        if _, ok := mm[member.User.ID]; !ok {
            mm[member.User.ID] = nil
            unique = append(unique, member)
        }
    }
    return unique
}

Why this slice has non-unique elements?

bwmarrin commented 5 years ago

Good question, I'll try to do some tests and see if I can recreate the issue.

Zamiell commented 5 years ago

Interestingly, I am actually getting the opposite problem: I have 341 members in my Discord guild/server, and iterating over guildMembers only yields 131 entries. Any idea why this could be the case? Is there some limit to the amount of people that the API can handle?

[edit] More info:

I am on the latest version (v19). And here is a print statement of the bug in question:

Sun Apr 14 15:03:54 UTC 2019 - len(guild.Members) = 106, guild.MemberCount = 341

So interestingly, MemberCount is correct, but the size of guildMembers is not... It seems to fluctuate and not be consistent between calls.

[edit2] The problem seems to go away once I do a RequestGuildMembers() call. Now I get:

Sun Apr 14 15:25:28 UTC 2019 - len(guild.Members) = 342, guild.MemberCount = 341

Which is more in line with what saulgoogman is experiencing.

bwmarrin commented 5 years ago

@Zamiell this sounds like a different issue and should probably have it's own issue - not get added into this one. Can you create a new issue for your question?

Zamiell commented 5 years ago

To be clear, now that I'm using RequestGuildMembers(), I'm also experiencing this issue - the size of len(guild.Members) will occasionally be larger than guild.MemberCount. But yes, I'll open a separate issue.

ghost commented 5 years ago

Good question, I'll try to do some tests and see if I can recreate the issue.

I just use RuquestGuildMembers() on Ready event.

Zamiell commented 5 years ago

I set up a Goroutine to redo RuquestGuildMembers() every 5 minutes, because I wasn't sure if it would stay updated. Do either of you know if that is necessary? Regardless, it could be contributing to the bug in question.

buffet commented 4 years ago

Here it seems like it's including members that are connected to voice chat twice.

jacksonludwig commented 3 years ago

I also can confirm that this bug is still a thing. It counts users in voice chat twice.

wagpa commented 1 year ago

I can also confirm that that exact bug is still there (using v0.26.1).