1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-01-20 19:47:12 +00:00

API: Add File.AttachmentURI for convenience

This commit is contained in:
diamondburned 2021-02-24 01:59:33 -08:00
parent 3713c9d404
commit f5dc90c2d4
2 changed files with 13 additions and 0 deletions

View file

@ -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.

View file

@ -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 {