From 33ee38cbf2713a7a20163d4c2c570429ede89a3d Mon Sep 17 00:00:00 2001 From: Shadat Rahman <46465883+hhaste@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:21:43 -0400 Subject: [PATCH] feat(UserGuilds)!: support with_counts parameter (#1500) --------- Co-authored-by: Fedor Lapshin --- restapi.go | 12 ++++++++---- restapi_test.go | 2 +- structs.go | 8 ++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/restapi.go b/restapi.go index 3aec73c..97d1b58 100644 --- a/restapi.go +++ b/restapi.go @@ -424,10 +424,11 @@ func (s *Session) UserGuildMember(guildID string, options ...RequestOption) (st } // UserGuilds returns an array of UserGuild structures for all guilds. -// limit : The number guilds that can be returned. (max 100) -// beforeID : If provided all guilds returned will be before given ID. -// afterID : If provided all guilds returned will be after given ID. -func (s *Session) UserGuilds(limit int, beforeID, afterID string, options ...RequestOption) (st []*UserGuild, err error) { +// limit : The number guilds that can be returned. (max 200) +// beforeID : If provided all guilds returned will be before given ID. +// afterID : If provided all guilds returned will be after given ID. +// withCounts : Whether to include approximate member and presence counts or not. +func (s *Session) UserGuilds(limit int, beforeID, afterID string, withCounts bool, options ...RequestOption) (st []*UserGuild, err error) { v := url.Values{} @@ -440,6 +441,9 @@ func (s *Session) UserGuilds(limit int, beforeID, afterID string, options ...Req if beforeID != "" { v.Set("before", beforeID) } + if withCounts { + v.Set("with_counts", "true") + } uri := EndpointUserGuilds("@me") diff --git a/restapi_test.go b/restapi_test.go index 56da575..bb922b9 100644 --- a/restapi_test.go +++ b/restapi_test.go @@ -106,7 +106,7 @@ func TestUserGuilds(t *testing.T) { t.Skip("Cannot TestUserGuilds, dg not set.") } - _, err := dg.UserGuilds(10, "", "") + _, err := dg.UserGuilds(10, "", "", false) if err != nil { t.Errorf(err.Error()) } diff --git a/structs.go b/structs.go index 21fb3e5..4df8bd5 100644 --- a/structs.go +++ b/structs.go @@ -1274,6 +1274,14 @@ type UserGuild struct { Owner bool `json:"owner"` Permissions int64 `json:"permissions,string"` Features []GuildFeature `json:"features"` + + // Approximate number of members in this guild. + // NOTE: this field is only filled when withCounts is true. + ApproximateMemberCount int `json:"approximate_member_count"` + + // Approximate number of non-offline members in this guild. + // NOTE: this field is only filled when withCounts is true. + ApproximatePresenceCount int `json:"approximate_presence_count"` } // GuildFeature indicates the presence of a feature in a guild