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.
|
// is also where you should get the instance from.
|
||||||
type MessageEdit struct {
|
type MessageEdit struct {
|
||||||
Content *string `json:"content,omitempty"`
|
Content *string `json:"content,omitempty"`
|
||||||
Components []MessageComponent `json:"components"`
|
Components *[]MessageComponent `json:"components,omitempty"`
|
||||||
Embeds []*MessageEmbed `json:"embeds"`
|
Embeds *[]*MessageEmbed `json:"embeds,omitempty"`
|
||||||
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
|
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
|
||||||
Flags MessageFlags `json:"flags,omitempty"`
|
Flags MessageFlags `json:"flags,omitempty"`
|
||||||
// Files to append to the message
|
// 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,
|
// SetEmbed is a convenience function for setting the embed,
|
||||||
// so you can chain commands.
|
// so you can chain commands.
|
||||||
func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit {
|
func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit {
|
||||||
m.Embeds = []*MessageEmbed{embed}
|
m.Embeds = &[]*MessageEmbed{embed}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEmbeds is a convenience function for setting the embeds,
|
// SetEmbeds is a convenience function for setting the embeds,
|
||||||
// so you can chain commands.
|
// so you can chain commands.
|
||||||
func (m *MessageEdit) SetEmbeds(embeds []*MessageEmbed) *MessageEdit {
|
func (m *MessageEdit) SetEmbeds(embeds []*MessageEmbed) *MessageEdit {
|
||||||
m.Embeds = embeds
|
m.Embeds = &embeds
|
||||||
return m
|
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.
|
// TODO: Remove this when compatibility is not required.
|
||||||
if m.Embed != nil {
|
if m.Embed != nil {
|
||||||
if m.Embeds == nil {
|
if m.Embeds == nil {
|
||||||
m.Embeds = []*MessageEmbed{m.Embed}
|
m.Embeds = &[]*MessageEmbed{m.Embed}
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("cannot specify both Embed and Embeds")
|
err = fmt.Errorf("cannot specify both Embed and Embeds")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, embed := range m.Embeds {
|
if m.Embeds != nil {
|
||||||
if embed.Type == "" {
|
for _, embed := range *m.Embeds {
|
||||||
embed.Type = "rich"
|
if embed.Type == "" {
|
||||||
|
embed.Type = "rich"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue