fix(message)!: omit empty Components and Embeds (#1483)
--------- Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
parent
afc57886f9
commit
7f80bc7978
2 changed files with 10 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
10
restapi.go
10
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue