From 140104fd6be1c36f02a37e2efd6b2ada177e2981 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Wed, 10 Jan 2024 11:13:57 +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 557cd719b..6c788bc92 100644 --- a/components.go +++ b/components.go @@ -177,6 +177,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"`