Skip to content

Commit

Permalink
Payload for member edit (#1122)
Browse files Browse the repository at this point in the history
* Create payload for Guild Member Edit

* Update rest API usage with new payload

* Update comment with ref to discord API

* Change data to pointer instead

* Change struct to just nick and roles

* Review comments

* feat(rest#GuildMemberEditComplex): return updated member and cosmetic changes

* feat(structs): renamed GuildMemberEditData to GuildMemberParams

* style(structs#GuildMemberParams): fix spacing

* fix(rest#GuildMemberEditComplex): use GuildMemberParams instead of GuildMemberEditData

Co-authored-by: nitroflap <fe.lap.prog@gmail.com>
  • Loading branch information
Jarvvski and FedorLap2006 committed Apr 4, 2022
1 parent 0c27ced commit c3c6c1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions restapi.go
Expand Up @@ -798,6 +798,21 @@ func (s *Session) GuildMemberEdit(guildID, userID string, roles []string) (err e
return
}

// GuildMemberEditComplex edits the nickname and roles of a member.
// guildID : The ID of a Guild.
// userID : The ID of a User.
// data : A GuildMemberEditData struct with the new nickname and roles
func (s *Session) GuildMemberEditComplex(guildID, userID string, data GuildMemberParams) (st *Member, err error) {
var body []byte
body, err = s.RequestWithBucketID("PATCH", EndpointGuildMember(guildID, userID), data, EndpointGuildMember(guildID, ""))
if err != nil {
return nil, err
}

err = unmarshal(body, &st)
return
}

// GuildMemberMove moves a guild member from one voice channel to another/none
// guildID : The ID of a Guild.
// userID : The ID of a User.
Expand Down
9 changes: 9 additions & 0 deletions structs.go
Expand Up @@ -1581,6 +1581,15 @@ type UserGuildSettingsEdit struct {
ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
}

// GuildMemberParams stores data needed to update a member
// https://discord.com/developers/docs/resources/guild#modify-guild-member
type GuildMemberParams struct {
// Value to set user's nickname to
Nick string `json:"nick,omitempty"`
// Array of role ids the member is assigned
Roles *[]string `json:"roles,omitempty"`
}

// An APIErrorMessage is an api error message returned from discord
type APIErrorMessage struct {
Code int `json:"code"`
Expand Down

0 comments on commit c3c6c1b

Please sign in to comment.