Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 3cee831

Browse files
authored
Add missing fields to GuildMemberParams (bwmarrin#1226)
* 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
1 parent 73ebf67 commit 3cee831

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

structs.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,10 +1727,57 @@ type UserGuildSettingsEdit struct {
17271727
// GuildMemberParams stores data needed to update a member
17281728
// https://discord.com/developers/docs/resources/guild#modify-guild-member
17291729
type GuildMemberParams struct {
1730-
// Value to set user's nickname to
1730+
// Value to set user's nickname to.
17311731
Nick string `json:"nick,omitempty"`
1732-
// Array of role ids the member is assigned
1732+
// Array of role ids the member is assigned.
17331733
Roles *[]string `json:"roles,omitempty"`
1734+
// ID of channel to move user to (if they are connected to voice).
1735+
// Set to "" to remove user from a voice channel.
1736+
ChannelID *string `json:"channel_id,omitempty"`
1737+
// Whether the user is muted in voice channels.
1738+
Mute *bool `json:"mute,omitempty"`
1739+
// Whether the user is deafened in voice channels.
1740+
Deaf *bool `json:"deaf,omitempty"`
1741+
// When the user's timeout will expire and the user will be able
1742+
// to communicate in the guild again (up to 28 days in the future).
1743+
// Set to time.Time{} to remove timeout.
1744+
CommunicationDisabledUntil *time.Time `json:"communication_disabled_until,omitempty"`
1745+
}
1746+
1747+
// MarshalJSON is a helper function to marshal GuildMemberParams.
1748+
func (p GuildMemberParams) MarshalJSON() (res []byte, err error) {
1749+
type guildMemberParams GuildMemberParams
1750+
v := struct {
1751+
guildMemberParams
1752+
ChannelID json.RawMessage `json:"channel_id,omitempty"`
1753+
CommunicationDisabledUntil json.RawMessage `json:"communication_disabled_until,omitempty"`
1754+
}{guildMemberParams: guildMemberParams(p)}
1755+
1756+
if p.ChannelID != nil {
1757+
if *p.ChannelID == "" {
1758+
v.ChannelID = json.RawMessage(`null`)
1759+
} else {
1760+
res, err = json.Marshal(p.ChannelID)
1761+
if err != nil {
1762+
return
1763+
}
1764+
v.ChannelID = res
1765+
}
1766+
}
1767+
1768+
if p.CommunicationDisabledUntil != nil {
1769+
if p.CommunicationDisabledUntil.IsZero() {
1770+
v.CommunicationDisabledUntil = json.RawMessage(`null`)
1771+
} else {
1772+
res, err = json.Marshal(p.CommunicationDisabledUntil)
1773+
if err != nil {
1774+
return
1775+
}
1776+
v.CommunicationDisabledUntil = res
1777+
}
1778+
}
1779+
1780+
return json.Marshal(v)
17341781
}
17351782

17361783
// An APIErrorMessage is an api error message returned from discord

0 commit comments

Comments
 (0)