Skip to content

Commit

Permalink
Add missing fields to GuildMemberParams (#1226)
Browse files Browse the repository at this point in the history
* feat(GuildMemberParams): add missing fields

Add the following fields to GuildMemberParams
* channel_id

* mute

* deaf

* communication_disabled_until

* fix(GuildMemberParams): null values

Fix null values on omitted fields
  • Loading branch information
FedorLap2006 committed Aug 17, 2022
1 parent 73ebf67 commit 3cee831
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions structs.go
Expand Up @@ -1727,10 +1727,57 @@ type UserGuildSettingsEdit struct {
// 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
// Value to set user's nickname to.
Nick string `json:"nick,omitempty"`
// Array of role ids the member is assigned
// Array of role ids the member is assigned.
Roles *[]string `json:"roles,omitempty"`
// ID of channel to move user to (if they are connected to voice).
// Set to "" to remove user from a voice channel.
ChannelID *string `json:"channel_id,omitempty"`
// Whether the user is muted in voice channels.
Mute *bool `json:"mute,omitempty"`
// Whether the user is deafened in voice channels.
Deaf *bool `json:"deaf,omitempty"`
// When the user's timeout will expire and the user will be able
// to communicate in the guild again (up to 28 days in the future).
// Set to time.Time{} to remove timeout.
CommunicationDisabledUntil *time.Time `json:"communication_disabled_until,omitempty"`
}

// MarshalJSON is a helper function to marshal GuildMemberParams.
func (p GuildMemberParams) MarshalJSON() (res []byte, err error) {
type guildMemberParams GuildMemberParams
v := struct {
guildMemberParams
ChannelID json.RawMessage `json:"channel_id,omitempty"`
CommunicationDisabledUntil json.RawMessage `json:"communication_disabled_until,omitempty"`
}{guildMemberParams: guildMemberParams(p)}

if p.ChannelID != nil {
if *p.ChannelID == "" {
v.ChannelID = json.RawMessage(`null`)
} else {
res, err = json.Marshal(p.ChannelID)
if err != nil {
return
}
v.ChannelID = res
}
}

if p.CommunicationDisabledUntil != nil {
if p.CommunicationDisabledUntil.IsZero() {
v.CommunicationDisabledUntil = json.RawMessage(`null`)
} else {
res, err = json.Marshal(p.CommunicationDisabledUntil)
if err != nil {
return
}
v.CommunicationDisabledUntil = res
}
}

return json.Marshal(v)
}

// An APIErrorMessage is an api error message returned from discord
Expand Down

0 comments on commit 3cee831

Please sign in to comment.