Skip to content

Commit

Permalink
fix(message)!: omit empty Components and Embeds (#1483)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
  • Loading branch information
AlexeyOplachko and FedorLap2006 committed Feb 2, 2024
1 parent afc5788 commit 7f80bc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down

0 comments on commit 7f80bc7

Please sign in to comment.