From 7f80bc7978818aeff90e28aa7d5d09839218ebe6 Mon Sep 17 00:00:00 2001 From: AlexeyOplachko <45398541+AlexeyOplachko@users.noreply.github.com> Date: Sat, 3 Feb 2024 01:59:38 +0200 Subject: [PATCH] fix(message)!: omit empty Components and Embeds (#1483) --------- Co-authored-by: Fedor Lapshin --- message.go | 8 ++++---- restapi.go | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/message.go b/message.go index b669e9b..41c1df7 100644 --- a/message.go +++ b/message.go @@ -251,8 +251,8 @@ type MessageSend struct { // is also where you should get the instance from. type MessageEdit struct { Content *string `json:"content,omitempty"` - Components []MessageComponent `json:"components"` - Embeds []*MessageEmbed `json:"embeds"` + Components *[]MessageComponent `json:"components,omitempty"` + Embeds *[]*MessageEmbed `json:"embeds,omitempty"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` Flags MessageFlags `json:"flags,omitempty"` // Files to append to the message @@ -286,14 +286,14 @@ func (m *MessageEdit) SetContent(str string) *MessageEdit { // SetEmbed is a convenience function for setting the embed, // so you can chain commands. func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit { - m.Embeds = []*MessageEmbed{embed} + m.Embeds = &[]*MessageEmbed{embed} return m } // SetEmbeds is a convenience function for setting the embeds, // so you can chain commands. func (m *MessageEdit) SetEmbeds(embeds []*MessageEmbed) *MessageEdit { - m.Embeds = embeds + m.Embeds = &embeds return m } diff --git a/restapi.go b/restapi.go index cc18d88..ea5ded3 100644 --- a/restapi.go +++ b/restapi.go @@ -1797,16 +1797,18 @@ func (s *Session) ChannelMessageEditComplex(m *MessageEdit, options ...RequestOp // TODO: Remove this when compatibility is not required. if m.Embed != nil { if m.Embeds == nil { - m.Embeds = []*MessageEmbed{m.Embed} + m.Embeds = &[]*MessageEmbed{m.Embed} } else { err = fmt.Errorf("cannot specify both Embed and Embeds") return } } - for _, embed := range m.Embeds { - if embed.Type == "" { - embed.Type = "rich" + if m.Embeds != nil { + for _, embed := range *m.Embeds { + if embed.Type == "" { + embed.Type = "rich" + } } }