Skip to content

Commit

Permalink
feat(UserGuilds): support with_counts parameter (#1500)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Fedor Lapshin <[email protected]>
  • Loading branch information
hhaste and FedorLap2006 authored Mar 15, 2024
1 parent 202785c commit 93cb440
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

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

Expand Down
2 changes: 1 addition & 1 deletion restapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
8 changes: 8 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93cb440

Please sign in to comment.