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

Add missing fields to GuildMemberParams #1226

Merged
merged 2 commits into from Aug 17, 2022
Merged
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
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