Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UserGuilds): support with_counts parameter #1500

Merged
merged 7 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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