From 493e23c1eb4147956e2412bef1f71f4b8fec4a4e Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Wed, 10 Jan 2024 11:16:15 +0300 Subject: [PATCH] fix(SelectMenuOption): omit empty Emoji field --- components.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/components.go b/components.go index 37adbe2bc..3fd13b12c 100644 --- a/components.go +++ b/components.go @@ -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 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"`