Skip to content

Commit

Permalink
Add ability to include embed with upload_file (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenbigfrog authored Jun 19, 2021
1 parent 32d4ffa commit d9643cd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/discordcr/rest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ module Discord
# [API docs for this method](https://discord.com/developers/docs/resources/channel#create-message)
# (same as `#create_message` -- this method implements form data bodies
# while `#create_message` implements JSON bodies)
def upload_file(channel_id : UInt64 | Snowflake, content : String?, file : IO, filename : String? = nil, spoiler : Bool = false)
def upload_file(channel_id : UInt64 | Snowflake, content : String?, file : IO, filename : String? = nil, embed : Embed? = nil, spoiler : Bool = false)
io = IO::Memory.new

unless filename
Expand All @@ -449,8 +449,14 @@ module Discord
end

builder = HTTP::FormData::Builder.new(io)
builder.field("content", content) if content
builder.file("file", file, HTTP::FormData::FileMetadata.new(filename: filename))
if content || embed
json = encode_tuple(
content: content,
embed: embed
)
builder.field("payload_json", json)
end
builder.finish

response = request(
Expand Down

0 comments on commit d9643cd

Please sign in to comment.