fix(message)!: omit empty Components and Embeds (#1483)

---------

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
AlexeyOplachko 2024-02-03 01:59:38 +02:00 committed by GitHub
parent afc57886f9
commit 7f80bc7978
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View file

@ -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
}

View file

@ -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"
}
}
}