Skip to content

Commit

Permalink
fix(SelectMenuOption): omit empty Emoji field
Browse files Browse the repository at this point in the history
  • Loading branch information
FedorLap2006 committed Jan 10, 2024
1 parent 8b9acb3 commit 0040bfc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ type SelectMenuOption struct {
Default bool `json:"default"`
}

// MarshalJSON is a method for marshalling SelectMenuOption to a JSON object.
func (o SelectMenuOption) MarshalJSON() ([]byte, error) {
type selectMenuOption SelectMenuOption

var emoji *ComponentEmoji
if o.Emoji.ID != "" || o.Emoji.Name != "" {
emoji = &o.Emoji
}

return json.Marshal(struct {
selectMenuOption
Emoji *ComponentEmoji `json:"emoji,omitempty"`
}{
selectMenuOption: selectMenuOption(o),
Emoji: emoji,
})
}

// SelectMenu represents select menu component.
type SelectMenu struct {
CustomID string `json:"custom_id,omitempty"`
Expand Down

0 comments on commit 0040bfc

Please sign in to comment.