DiscordInteractions.API (discord_interactions v0.1.0)
View SourceDiscord REST API client.
Summary
Functions
Batch updates permissions for multiple commands in a guild.
Bulk overwrites all global commands.
Bulk overwrites all commands in a guild.
Creates a followup message for an interaction.
Creates a new global command.
Creates a new command in a guild.
Creates an initial response to an interaction.
Perform a DELETE request.
Perform a DELETE request.
Deletes a followup message for an interaction.
Deletes a global command.
Deletes a command from a guild.
Deletes the initial response to an interaction.
Edits a followup message for an interaction.
Edits the initial response to an interaction.
Perform a GET request.
Perform a GET request.
Gets permissions for a specific command in a guild.
Gets a followup message for an interaction.
Gets a specific global command by ID.
Gets all global commands for the application.
Gets a specific command in a guild.
Gets permissions for all commands in a guild.
Gets all commands for a specific guild.
Gets the initial response to an interaction.
Perform a HEAD request.
Perform a HEAD request.
Creates a new API client with the given token.
Perform a OPTIONS request.
Perform a OPTIONS request.
Perform a PATCH request.
Perform a PATCH request.
Perform a POST request.
Perform a POST request.
Perform a PUT request.
Perform a PUT request.
Perform a request.
Perform request and raise in case of error.
Perform a TRACE request.
Perform a TRACE request.
Updates permissions for a specific command in a guild.
Updates an existing global command.
Updates an existing command in a guild.
Types
@type application_id() :: String.t()
@type client() :: term()
@type command() :: map()
@type command_id() :: String.t()
@type commands() :: [command()]
@type error() :: {:error, any()}
@type guild_id() :: String.t()
@type interaction_callback_response() :: map()
@type interaction_id() :: String.t()
@type interaction_response() :: map()
@type interaction_token() :: String.t()
@type message() :: map()
@type message_id() :: String.t()
@type option() :: {:method, Tesla.Env.method()} | {:url, Tesla.Env.url()} | {:query, Tesla.Env.query()} | {:headers, Tesla.Env.headers()} | {:body, Tesla.Env.body()} | {:opts, Tesla.Env.opts()}
Options that may be passed to a request function. See request/2
for detailed descriptions.
@type permissions() :: map()
Functions
@spec batch_update_command_permissions(client(), guild_id(), [permissions()]) :: {:ok, [permissions()]} | error()
Batch updates permissions for multiple commands in a guild.
Examples
iex> permissions = [
...> %{id: "CMD_ID_1", permissions: [%{id: "ROLE_ID", type: 1, permission: true}]},
...> %{id: "CMD_ID_2", permissions: [%{id: "USER_ID", type: 2, permission: true}]}
...> ]
iex> {:ok, updated} = DiscordInteractions.Client.batch_update_command_permissions(client, "GUILD_ID", permissions)
Bulk overwrites all global commands.
Examples
iex> commands = [%{name: "cmd1", description: "Command 1"}, %{name: "cmd2", description: "Command 2"}]
iex> {:ok, updated} = DiscordInteractions.Client.bulk_overwrite_global_commands(client, commands)
@spec bulk_overwrite_guild_commands(client(), guild_id(), commands()) :: {:ok, commands()} | error()
Bulk overwrites all commands in a guild.
Examples
iex> commands = [%{name: "cmd1", description: "Command 1"}, %{name: "cmd2", description: "Command 2"}]
iex> {:ok, updated} = DiscordInteractions.Client.bulk_overwrite_guild_commands(client, "GUILD_ID", commands)
@spec create_followup_message(client(), interaction_token(), message()) :: {:ok, message()} | error()
Creates a followup message for an interaction.
Examples
iex> message = %{content: "Followup message"}
iex> {:ok, created} = DiscordInteractions.Client.create_followup_message(client, "INTERACTION_TOKEN", message)
Creates a new global command.
Examples
iex> command = %{name: "test", description: "A test command", type: 1}
iex> {:ok, created} = DiscordInteractions.Client.create_global_command(client, command)
Creates a new command in a guild.
Examples
iex> command = %{name: "test", description: "A test command", type: 1}
iex> {:ok, created} = DiscordInteractions.Client.create_guild_command(client, "GUILD_ID", command)
@spec create_interaction_response( client(), interaction_id(), interaction_token(), interaction_response() ) :: :ok | {:ok, interaction_callback_response()} | error()
Creates an initial response to an interaction.
Examples
iex> response = %{type: 4, data: %{content: "Hello!"}}
iex> :ok = DiscordInteractions.Client.create_interaction_response(client, "INTERACTION_ID", "INTERACTION_TOKEN", response)
@spec delete(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.result()
Perform a DELETE request.
See request/1
or request/2
for options definition.
delete("/users")
delete("/users", query: [scope: "admin"])
delete(client, "/users")
delete(client, "/users", query: [scope: "admin"])
delete(client, "/users", body: %{name: "Jon"})
@spec delete!(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.t() | no_return()
Perform a DELETE request.
See request!/1
or request!/2
for options definition.
delete!("/users")
delete!("/users", query: [scope: "admin"])
delete!(client, "/users")
delete!(client, "/users", query: [scope: "admin"])
delete!(client, "/users", body: %{name: "Jon"})
@spec delete_followup_message(client(), interaction_token(), message_id()) :: :ok | error()
Deletes a followup message for an interaction.
Examples
iex> :ok = DiscordInteractions.Client.delete_followup_message(client, "INTERACTION_TOKEN", "MESSAGE_ID")
@spec delete_global_command(client(), command_id()) :: :ok | error()
Deletes a global command.
Examples
iex> :ok = DiscordInteractions.Client.delete_global_command(client, "CMD_ID")
@spec delete_guild_command(client(), guild_id(), command_id()) :: :ok | error()
Deletes a command from a guild.
Examples
iex> :ok = DiscordInteractions.Client.delete_guild_command(client, "GUILD_ID", "CMD_ID")
@spec delete_original_interaction_response(client(), interaction_token()) :: :ok | error()
Deletes the initial response to an interaction.
Examples
iex> :ok = DiscordInteractions.Client.delete_original_interaction_response(client, "INTERACTION_TOKEN")
@spec edit_followup_message(client(), interaction_token(), message_id(), message()) :: {:ok, message()} | error()
Edits a followup message for an interaction.
Examples
iex> message = %{content: "Updated followup"}
iex> {:ok, updated} = DiscordInteractions.Client.edit_followup_message(client, "INTERACTION_TOKEN", "MESSAGE_ID", message)
@spec edit_original_interaction_response(client(), interaction_token(), message()) :: {:ok, message()} | error()
Edits the initial response to an interaction.
Examples
iex> message = %{content: "Updated content"}
iex> {:ok, updated} = DiscordInteractions.Client.edit_original_interaction_response(client, "INTERACTION_TOKEN", message)
@spec get(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.result()
Perform a GET request.
See request/1
or request/2
for options definition.
get("/users")
get("/users", query: [scope: "admin"])
get(client, "/users")
get(client, "/users", query: [scope: "admin"])
get(client, "/users", body: %{name: "Jon"})
@spec get!(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.t() | no_return()
Perform a GET request.
See request!/1
or request!/2
for options definition.
get!("/users")
get!("/users", query: [scope: "admin"])
get!(client, "/users")
get!(client, "/users", query: [scope: "admin"])
get!(client, "/users", body: %{name: "Jon"})
@spec get_command_permissions(client(), guild_id(), command_id()) :: {:ok, permissions()} | error()
Gets permissions for a specific command in a guild.
Examples
iex> {:ok, permissions} = DiscordInteractions.Client.get_command_permissions(client, "GUILD_ID", "CMD_ID")
@spec get_followup_message(client(), interaction_token(), message_id()) :: {:ok, message()} | error()
Gets a followup message for an interaction.
Examples
iex> {:ok, message} = DiscordInteractions.Client.get_followup_message(client, "INTERACTION_TOKEN", "MESSAGE_ID")
@spec get_global_command(client(), command_id()) :: {:ok, command()} | error()
Gets a specific global command by ID.
Examples
iex> {:ok, command} = DiscordInteractions.Client.get_global_command(client, "CMD_ID")
Gets all global commands for the application.
Examples
iex> {:ok, commands} = DiscordInteractions.Client.get_global_commands(client)
@spec get_guild_command(client(), guild_id(), command_id()) :: {:ok, command()} | error()
Gets a specific command in a guild.
Examples
iex> {:ok, command} = DiscordInteractions.Client.get_guild_command(client, "GUILD_ID", "CMD_ID")
@spec get_guild_command_permissions(client(), guild_id()) :: {:ok, [permissions()]} | error()
Gets permissions for all commands in a guild.
Examples
iex> {:ok, permissions} = DiscordInteractions.Client.get_guild_command_permissions(client, "GUILD_ID")
Gets all commands for a specific guild.
Examples
iex> {:ok, commands} = DiscordInteractions.Client.get_guild_commands(client, "GUILD_ID")
@spec get_original_interaction_response(client(), interaction_token()) :: {:ok, message()} | error()
Gets the initial response to an interaction.
Examples
iex> {:ok, message} = DiscordInteractions.Client.get_original_interaction_response(client, "INTERACTION_TOKEN")
@spec head(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.result()
Perform a HEAD request.
See request/1
or request/2
for options definition.
head("/users")
head("/users", query: [scope: "admin"])
head(client, "/users")
head(client, "/users", query: [scope: "admin"])
head(client, "/users", body: %{name: "Jon"})
@spec head!(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.t() | no_return()
Perform a HEAD request.
See request!/1
or request!/2
for options definition.
head!("/users")
head!("/users", query: [scope: "admin"])
head!(client, "/users")
head!(client, "/users", query: [scope: "admin"])
head!(client, "/users", body: %{name: "Jon"})
Creates a new API client with the given token.
Examples
iex> client = DiscordInteractions.Client.new(application_id: "APP_ID", token: "BOT_TOKEN")
@spec options(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.result()
Perform a OPTIONS request.
See request/1
or request/2
for options definition.
options("/users")
options("/users", query: [scope: "admin"])
options(client, "/users")
options(client, "/users", query: [scope: "admin"])
options(client, "/users", body: %{name: "Jon"})
@spec options!(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.t() | no_return()
Perform a OPTIONS request.
See request!/1
or request!/2
for options definition.
options!("/users")
options!("/users", query: [scope: "admin"])
options!(client, "/users")
options!(client, "/users", query: [scope: "admin"])
options!(client, "/users", body: %{name: "Jon"})
@spec patch(Tesla.Env.client(), Tesla.Env.url(), Tesla.Env.body(), [option()]) :: Tesla.Env.result()
Perform a PATCH request.
See request/1
or request/2
for options definition.
patch("/users", %{name: "Jon"})
patch("/users", %{name: "Jon"}, query: [scope: "admin"])
patch(client, "/users", %{name: "Jon"})
patch(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
@spec patch!(Tesla.Env.client(), Tesla.Env.url(), Tesla.Env.body(), [option()]) :: Tesla.Env.t() | no_return()
Perform a PATCH request.
See request!/1
or request!/2
for options definition.
patch!("/users", %{name: "Jon"})
patch!("/users", %{name: "Jon"}, query: [scope: "admin"])
patch!(client, "/users", %{name: "Jon"})
patch!(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
@spec post(Tesla.Env.client(), Tesla.Env.url(), Tesla.Env.body(), [option()]) :: Tesla.Env.result()
Perform a POST request.
See request/1
or request/2
for options definition.
post("/users", %{name: "Jon"})
post("/users", %{name: "Jon"}, query: [scope: "admin"])
post(client, "/users", %{name: "Jon"})
post(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
@spec post!(Tesla.Env.client(), Tesla.Env.url(), Tesla.Env.body(), [option()]) :: Tesla.Env.t() | no_return()
Perform a POST request.
See request!/1
or request!/2
for options definition.
post!("/users", %{name: "Jon"})
post!("/users", %{name: "Jon"}, query: [scope: "admin"])
post!(client, "/users", %{name: "Jon"})
post!(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
@spec put(Tesla.Env.client(), Tesla.Env.url(), Tesla.Env.body(), [option()]) :: Tesla.Env.result()
Perform a PUT request.
See request/1
or request/2
for options definition.
put("/users", %{name: "Jon"})
put("/users", %{name: "Jon"}, query: [scope: "admin"])
put(client, "/users", %{name: "Jon"})
put(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
@spec put!(Tesla.Env.client(), Tesla.Env.url(), Tesla.Env.body(), [option()]) :: Tesla.Env.t() | no_return()
Perform a PUT request.
See request!/1
or request!/2
for options definition.
put!("/users", %{name: "Jon"})
put!("/users", %{name: "Jon"}, query: [scope: "admin"])
put!(client, "/users", %{name: "Jon"})
put!(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
@spec request(Tesla.Env.client(), [option()]) :: Tesla.Env.result()
Perform a request.
Options
:method
- the request method, one of [:head
,:get
,:delete
,:trace
,:options
,:post
,:put
,:patch
]:url
- either full url e.g. "http://example.com/some/path" or just "/some/path" if usingTesla.Middleware.BaseUrl
:query
- a keyword list of query params, e.g.[page: 1, per_page: 100]
:headers
- a keyword list of headers, e.g.[{"content-type", "text/plain"}]
:body
- depends on used middleware:- by default it can be a binary
- if using e.g. JSON encoding middleware it can be a nested map
- if adapter supports it it can be a Stream with any of the above
:opts
- custom, per-request middleware or adapter options
Examples
ExampleApi.request(method: :get, url: "/users/path")
# use shortcut methods
ExampleApi.get("/users/1")
ExampleApi.post(client, "/users", %{name: "Jon"})
@spec request!(Tesla.Env.client(), [option()]) :: Tesla.Env.t() | no_return()
Perform request and raise in case of error.
This is similar to request/2
behaviour from Tesla 0.x
See request/2
for list of available options.
@spec trace(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.result()
Perform a TRACE request.
See request/1
or request/2
for options definition.
trace("/users")
trace("/users", query: [scope: "admin"])
trace(client, "/users")
trace(client, "/users", query: [scope: "admin"])
trace(client, "/users", body: %{name: "Jon"})
@spec trace!(Tesla.Env.client(), Tesla.Env.url(), [option()]) :: Tesla.Env.t() | no_return()
Perform a TRACE request.
See request!/1
or request!/2
for options definition.
trace!("/users")
trace!("/users", query: [scope: "admin"])
trace!(client, "/users")
trace!(client, "/users", query: [scope: "admin"])
trace!(client, "/users", body: %{name: "Jon"})
@spec update_command_permissions(client(), guild_id(), command_id(), permissions()) :: {:ok, permissions()} | error()
Updates permissions for a specific command in a guild.
Examples
iex> permissions = %{permissions: [%{id: "ROLE_ID", type: 1, permission: true}]}
iex> {:ok, updated} = DiscordInteractions.Client.update_command_permissions(client, "GUILD_ID", "CMD_ID", permissions)
@spec update_global_command(client(), command_id(), command()) :: {:ok, command()} | error()
Updates an existing global command.
Examples
iex> command = %{name: "test", description: "Updated description", type: 1}
iex> {:ok, updated} = DiscordInteractions.Client.update_global_command(client, "CMD_ID", command)
@spec update_guild_command(client(), guild_id(), command_id(), command()) :: {:ok, command()} | error()
Updates an existing command in a guild.
Examples
iex> command = %{name: "test", description: "Updated description", type: 1}
iex> {:ok, updated} = DiscordInteractions.Client.update_guild_command(client, "GUILD_ID", "CMD_ID", command)