Skip to content

Commit

Permalink
Merge pull request #560 from Kraigie/jb3/fix-files
Browse files Browse the repository at this point in the history
Re-support uploading files from memory
  • Loading branch information
jb3 authored Apr 22, 2024
2 parents 3d8d548 + 68d3c46 commit 5107db0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/nostrum/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ defmodule Nostrum.Api do
do: create_message(channel_id, Map.new(options))

def create_message(channel_id, %{} = options) when is_snowflake(channel_id) do
options = prepare_allowed_mentions(options) |> combine_embeds()
options = prepare_allowed_mentions(options) |> combine_embeds() |> combine_files()

request(:post, Constants.channel_messages(channel_id), options)
|> handle_request_with_decode({:struct, Message})
Expand Down Expand Up @@ -348,7 +348,7 @@ defmodule Nostrum.Api do

def edit_message(channel_id, message_id, %{} = options)
when is_snowflake(channel_id) and is_snowflake(message_id) do
options = prepare_allowed_mentions(options) |> combine_embeds()
options = prepare_allowed_mentions(options) |> combine_embeds() |> combine_files()

request(:patch, Constants.channel_message(channel_id, message_id), options)
|> handle_request_with_decode({:struct, Message})
Expand Down Expand Up @@ -3123,7 +3123,7 @@ defmodule Nostrum.Api do
request(
:post,
Constants.webhook_token(webhook_id, webhook_token),
combine_embeds(args),
combine_embeds(args) |> combine_files(),
params
)
|> handle_request_with_decode({:struct, Message})
Expand All @@ -3146,7 +3146,7 @@ defmodule Nostrum.Api do
request(
:patch,
Constants.webhook_message_edit(webhook_id, webhook_token, message_id),
combine_embeds(args)
combine_embeds(args) |> combine_files()
)
|> handle_request_with_decode({:struct, Message})
end
Expand Down Expand Up @@ -3556,7 +3556,11 @@ defmodule Nostrum.Api do
"""
@spec create_interaction_response(Interaction.id(), Interaction.token(), map()) :: {:ok} | error
def create_interaction_response(id, token, options) do
request(:post, Constants.interaction_callback(id, token), combine_embeds(options))
request(
:post,
Constants.interaction_callback(id, token),
combine_embeds(options) |> combine_files()
)
end

def create_interaction_response!(id, token, response) do
Expand Down Expand Up @@ -3604,7 +3608,11 @@ defmodule Nostrum.Api do
@spec edit_interaction_response(User.id(), Interaction.token(), map()) ::
{:ok, Message.t()} | error
def edit_interaction_response(id \\ Me.get().id, token, response) do
request(:patch, Constants.interaction_callback_original(id, token), combine_embeds(response))
request(
:patch,
Constants.interaction_callback_original(id, token),
combine_embeds(response) |> combine_files()
)
|> handle_request_with_decode({:struct, Message})
end

Expand Down

0 comments on commit 5107db0

Please # to comment.