Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 410cf4f

Browse files
Add files to MessageEdit (bwmarrin#1253)
* Add files to MessageEdit * Remove files from json Co-authored-by: Fedor Lapshin <[email protected]> Co-authored-by: Fedor Lapshin <[email protected]>
1 parent 1ff58d4 commit 410cf4f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

message.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ type MessageEdit struct {
249249
Embeds []*MessageEmbed `json:"embeds"`
250250
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
251251
Flags MessageFlags `json:"flags,omitempty"`
252+
// Files to append to the message
253+
Files []*File `json:"-"`
254+
// Overwrite existing attachments
255+
Attachments *[]*MessageAttachment `json:"attachments,omitempty"`
252256

253257
ID string
254258
Channel string

restapi.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,19 @@ func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err er
17291729
embed.Type = "rich"
17301730
}
17311731
}
1732-
response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(m.Channel, m.ID), m, EndpointChannelMessage(m.Channel, ""))
1732+
1733+
endpoint := EndpointChannelMessage(m.Channel, m.ID)
1734+
1735+
var response []byte
1736+
if len(m.Files) > 0 {
1737+
contentType, body, encodeErr := MultipartBodyWithJSON(m, m.Files)
1738+
if encodeErr != nil {
1739+
return st, encodeErr
1740+
}
1741+
response, err = s.request("PATCH", endpoint, contentType, body, EndpointChannelMessage(m.Channel, ""), 0)
1742+
} else {
1743+
response, err = s.RequestWithBucketID("PATCH", endpoint, m, EndpointChannelMessage(m.Channel, ""))
1744+
}
17331745
if err != nil {
17341746
return
17351747
}

0 commit comments

Comments
 (0)