Skip to content

Commit

Permalink
Allow setting bool properties of ChannelEdit to false (bwmarrin#1199)
Browse files Browse the repository at this point in the history
Setting e.g. ChannelEdit.Archived = false is currently not possible
as go will treat a false as empty and will omit the property
from the JSON object.
  • Loading branch information
iokill authored Jul 29, 2022
1 parent 039e685 commit 8b18bf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions examples/threads/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func main() {
games[m.ChannelID] = time.Now()
<-time.After(timeout)
if time.Since(games[m.ChannelID]) >= timeout {
archived := true
locked := true
_, err := s.ChannelEditComplex(m.ChannelID, &discordgo.ChannelEdit{
Archived: true,
Locked: true,
Archived: &archived,
Locked: &locked,
})
if err != nil {
panic(err)
Expand Down
10 changes: 5 additions & 5 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (c *Channel) IsThread() bool {
type ChannelEdit struct {
Name string `json:"name,omitempty"`
Topic string `json:"topic,omitempty"`
NSFW bool `json:"nsfw,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
Position int `json:"position"`
Bitrate int `json:"bitrate,omitempty"`
UserLimit int `json:"user_limit,omitempty"`
Expand All @@ -370,10 +370,10 @@ type ChannelEdit struct {

// NOTE: threads only

Archived bool `json:"archived,omitempty"`
AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
Locked bool `json:"locked,bool"`
Invitable bool `json:"invitable,omitempty"`
Archived *bool `json:"archived,omitempty"`
AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
Locked *bool `json:"locked,omitempty"`
Invitable *bool `json:"invitable,omitempty"`
}

// A ChannelFollow holds data returned after following a news channel
Expand Down

0 comments on commit 8b18bf4

Please sign in to comment.