feat(UserGuilds)!: support with_counts parameter (#1500)

---------

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
Shadat Rahman 2024-03-15 11:21:43 -04:00 committed by Fedor Lapshin
parent 202785c50b
commit 33ee38cbf2
No known key found for this signature in database
GPG key ID: 492D745FB49D2DAB
3 changed files with 17 additions and 5 deletions

View file

@ -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")

View file

@ -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())
}

View file

@ -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