EDA.API.Webhook (EDA v0.3.0)

Copy Markdown View Source

REST API endpoints for Discord webhooks.

All functions return {:ok, result} or {:error, reason}.

Summary

Functions

Creates a webhook for a channel.

Deletes a webhook.

Deletes a message previously sent by a webhook.

Edits a message previously sent by a webhook.

Gets a webhook by ID.

Gets a message previously sent by a webhook.

Gets webhooks for a channel.

Gets webhooks for a guild.

Modifies a webhook.

Functions

create(channel_id, opts)

@spec create(String.t() | integer(), map()) :: {:ok, map()} | {:error, term()}

Creates a webhook for a channel.

delete(webhook_id)

@spec delete(String.t() | integer()) :: :ok | {:error, term()}

Deletes a webhook.

delete_message(webhook_id, webhook_token, message_id)

@spec delete_message(String.t() | integer(), String.t(), String.t() | integer()) ::
  :ok | {:error, term()}

Deletes a message previously sent by a webhook.

Uses webhook token authentication (no bot token required).

Examples

:ok = Webhook.delete_message(webhook_id, token, message_id)

edit_message(webhook_id, webhook_token, message_id, opts)

@spec edit_message(
  String.t() | integer(),
  String.t(),
  String.t() | integer(),
  map() | keyword()
) :: {:ok, map()} | {:error, term()}

Edits a message previously sent by a webhook.

Accepts a map or keyword list of message fields to update (content, embeds, components, allowed_mentions). Supports file attachments via keyword opts.

Examples

{:ok, edited} = Webhook.edit_message(wh_id, token, msg_id, %{content: "updated"})
{:ok, edited} = Webhook.edit_message(wh_id, token, msg_id, content: "updated")

execute(webhook_id, webhook_token, opts)

@spec execute(String.t() | integer(), String.t(), map() | keyword()) ::
  {:ok, map()} | {:error, term()}

Executes a webhook.

Pass wait: true in opts to receive the created message back (required for subsequent get_message/3, edit_message/4, delete_message/3). Without wait: true, Discord returns 204 No Content.

get(webhook_id)

@spec get(String.t() | integer()) :: {:ok, map()} | {:error, term()}

Gets a webhook by ID.

get_message(webhook_id, webhook_token, message_id)

@spec get_message(String.t() | integer(), String.t(), String.t() | integer()) ::
  {:ok, map()} | {:error, term()}

Gets a message previously sent by a webhook.

Uses webhook token authentication (no bot token required).

Examples

{:ok, msg} = Webhook.get_message(webhook_id, token, message_id)

list_channel(channel_id)

@spec list_channel(String.t() | integer()) :: {:ok, [map()]} | {:error, term()}

Gets webhooks for a channel.

list_guild(guild_id)

@spec list_guild(String.t() | integer()) :: {:ok, [map()]} | {:error, term()}

Gets webhooks for a guild.

modify(webhook_id, opts)

@spec modify(String.t() | integer(), map()) :: {:ok, map()} | {:error, term()}

Modifies a webhook.