Skip to content

Commit f5dc90c

Browse files
committed
API: Add File.AttachmentURI for convenience
1 parent 3713c9d commit f5dc90c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

api/send.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ type SendMessageData struct {
102102
// Embed is embedded rich content.
103103
Embed *discord.Embed `json:"embed,omitempty"`
104104

105+
// Files is the list of file attachments to be uploaded. To reference a file
106+
// in an embed, use (sendpart.File).AttachmentURI().
105107
Files []sendpart.File `json:"-"`
106108

107109
// AllowedMentions are the allowed mentions for a message.

utils/sendpart/sendpart.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sendpart
33
import (
44
"io"
55
"mime/multipart"
6+
"net/url"
67
"strconv"
78

89
"github.com/diamondburned/arikawa/v2/utils/httputil"
@@ -16,6 +17,16 @@ type File struct {
1617
Reader io.Reader
1718
}
1819

20+
// AttachmentURI returns the file encoded using the attachment URI required for
21+
// embedding an attachment image.
22+
func (f File) AttachmentURI() string {
23+
u := url.URL{
24+
Scheme: "attachment",
25+
Path: f.Name,
26+
}
27+
return u.String()
28+
}
29+
1930
// DataMultipartWriter is a MultipartWriter that also contains data that's
2031
// JSON-marshalable.
2132
type DataMultipartWriter interface {

0 commit comments

Comments
 (0)