diff --git a/api/send.go b/api/send.go index ef1990b..772935a 100644 --- a/api/send.go +++ b/api/send.go @@ -102,6 +102,8 @@ type SendMessageData struct { // Embed is embedded rich content. Embed *discord.Embed `json:"embed,omitempty"` + // Files is the list of file attachments to be uploaded. To reference a file + // in an embed, use (sendpart.File).AttachmentURI(). Files []sendpart.File `json:"-"` // AllowedMentions are the allowed mentions for a message. diff --git a/utils/sendpart/sendpart.go b/utils/sendpart/sendpart.go index 47936ce..1b3fbcb 100644 --- a/utils/sendpart/sendpart.go +++ b/utils/sendpart/sendpart.go @@ -3,6 +3,7 @@ package sendpart import ( "io" "mime/multipart" + "net/url" "strconv" "github.com/diamondburned/arikawa/v2/utils/httputil" @@ -16,6 +17,16 @@ type File struct { Reader io.Reader } +// AttachmentURI returns the file encoded using the attachment URI required for +// embedding an attachment image. +func (f File) AttachmentURI() string { + u := url.URL{ + Scheme: "attachment", + Path: f.Name, + } + return u.String() +} + // DataMultipartWriter is a MultipartWriter that also contains data that's // JSON-marshalable. type DataMultipartWriter interface {