From 0bec62f96c1596656d4504f8a031068d0a67623d Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Sat, 19 Oct 2019 22:54:18 +0800 Subject: [PATCH] go: discord/backend: Add temporary workaround to discordgo's duplication issue --- GoBot/discord/backend/members.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/GoBot/discord/backend/members.go b/GoBot/discord/backend/members.go index c18e27c..03c043a 100644 --- a/GoBot/discord/backend/members.go +++ b/GoBot/discord/backend/members.go @@ -24,7 +24,17 @@ func GetAllMembers(s *discordgo.Session) ([]*discordgo.Member, error) { if err != nil { return nil, err } - return guild.Members, nil + //TODO Deduplication hack until discordgo fixes this. + deduplicationCache := make(map[string]bool) + dedupedArray := make([]*discordgo.Member, 0) + for _, v := range guild.Members { + if deduplicationCache[v.User.ID] { + continue + } + dedupedArray = append(dedupedArray, v) + deduplicationCache[v.User.ID] = true + } + return dedupedArray, nil } func GetMemberFromUserFriendlyName(s *discordgo.Session, user string) (*discordgo.Member, error) {