Add files to MessageEdit (#1253)

* Add files to MessageEdit

* Remove files from json

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>

Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
Dan Dryaev 2022-10-07 11:47:55 +00:00 committed by GitHub
parent 1ff58d47ef
commit 410cf4fac5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -249,6 +249,10 @@ type MessageEdit struct {
Embeds []*MessageEmbed `json:"embeds"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
Flags MessageFlags `json:"flags,omitempty"`
// Files to append to the message
Files []*File `json:"-"`
// Overwrite existing attachments
Attachments *[]*MessageAttachment `json:"attachments,omitempty"`
ID string
Channel string

View file

@ -1729,7 +1729,19 @@ func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err er
embed.Type = "rich"
}
}
response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, ""))
endpoint := EndpointChannelMessage(m.Channel, m.ID)
var response []byte
if len(m.Files) > 0 {
contentType, body, encodeErr := MultipartBodyWithJSON(m, m.Files)
if encodeErr != nil {
return st, encodeErr
}
response, err = s.request("PATCH", endpoint, contentType, body, EndpointChannelMessage(m.Channel, ""), 0)
} else {
response, err = s.RequestWithBucketID("PATCH", endpoint, m, EndpointChannelMessage(m.Channel, ""))
}
if err != nil {
return
}