Skip to content

Commit

Permalink
Added Guild Members Search Function (#1150)
Browse files Browse the repository at this point in the history
* Added Guild Members Search Function

* Updated method name to be consistent with other endpoints

* Refactored and moved GuildMembersSearch method for consistency
  • Loading branch information
Pancake-e committed Apr 4, 2022
1 parent 4ef1d50 commit 7e3d187
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions endpoints.go
Expand Up @@ -72,6 +72,7 @@ var (
EndpointGuildPreview = func(gID string) string { return EndpointGuilds + gID + "/preview" }
EndpointGuildChannels = func(gID string) string { return EndpointGuilds + gID + "/channels" }
EndpointGuildMembers = func(gID string) string { return EndpointGuilds + gID + "/members" }
EndpointGuildMembersSearch = func(gID string) string { return EndpointGuildMembers(gID) + "/search" }
EndpointGuildMember = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID }
EndpointGuildMemberRole = func(gID, uID, rID string) string { return EndpointGuilds + gID + "/members/" + uID + "/roles/" + rID }
EndpointGuildBans = func(gID string) string { return EndpointGuilds + gID + "/bans" }
Expand Down
23 changes: 23 additions & 0 deletions restapi.go
Expand Up @@ -696,6 +696,29 @@ func (s *Session) GuildMembers(guildID string, after string, limit int) (st []*M
return
}

// GuildMembersSearch returns a list of guild member objects whose username or nickname starts with a provided string
// guildID : The ID of a Guild
// query : Query string to match username(s) and nickname(s) against
// limit : Max number of members to return (default 1, min 1, max 1000)
func (s *Session) GuildMembersSearch(guildID, query string, limit int) (st []*Member, err error) {

uri := EndpointGuildMembersSearch(guildID)

queryParams := url.Values{}
queryParams.Set("query", query)
if limit > 1 {
queryParams.Set("limit", strconv.Itoa(limit))
}

body, err := s.RequestWithBucketID("GET", uri+"?"+queryParams.Encode(), nil, uri)
if err != nil {
return
}

err = unmarshal(body, &st)
return
}

// GuildMember returns a member of a guild.
// guildID : The ID of a Guild.
// userID : The ID of a User
Expand Down

0 comments on commit 7e3d187

Please sign in to comment.