REST API endpoints for Discord messages.
All functions return {:ok, result} or {:error, reason}.
Summary
Functions
Bulk deletes messages (2-100, not older than 14 days).
Creates a message in a channel.
Deletes a message.
Edits a message.
Forwards a message to another channel.
Gets a message by ID.
Retrieves message history from a channel with automatic pagination.
Gets messages from a channel.
Pins a message in a channel.
Gets pinned messages in a channel, paginating automatically.
Gets one page of a channel's pins.
Purges messages from a channel with automatic chunking and 14-day filtering.
Replies to a message, automatically setting message_reference.
Returns a lazy Stream that yields messages from a channel, page by page.
Unpins a message from a channel.
Functions
Bulk deletes messages (2-100, not older than 14 days).
@spec create(String.t() | integer(), String.t() | map() | keyword()) :: {:ok, map()} | {:error, term()}
Creates a message in a channel.
Parameters
channel_id- The ID of the channelcontent- Message content (string), full message payload (map), or keyword options
Examples
EDA.API.Message.create(channel_id, "Hello!")
EDA.API.Message.create(channel_id, content: "Look!", embeds: [embed])
EDA.API.Message.create(channel_id, content: "File!", files: [file])
Deletes a message.
@spec edit(String.t() | integer(), String.t() | integer(), map() | keyword()) :: {:ok, map()} | {:error, term()}
Edits a message.
@spec forward(String.t() | integer(), String.t() | integer(), String.t() | integer()) :: {:ok, map()} | {:error, term()}
Forwards a message to another channel.
Creates a message reference with type: 1 (forward) pointing to the original message.
Examples
EDA.API.Message.forward(target_channel_id, source_channel_id, message_id)
Gets a message by ID.
@spec history(String.t() | integer(), pos_integer() | :infinity, keyword()) :: {:ok, [map()]} | {:error, term()}
Retrieves message history from a channel with automatic pagination.
Handles Discord's 100-message-per-request limit transparently.
Supports :infinity to retrieve all messages.
Options
:before- snowflake ID, get messages before this:after- snowflake ID, get messages after this:around- snowflake ID, get messages around this (single page, max 100)
Examples
{:ok, msgs} = EDA.API.Message.history(channel_id, 250)
{:ok, msgs} = EDA.API.Message.history(channel_id, 500, before: msg_id)
{:ok, msgs} = EDA.API.Message.history(channel_id, :infinity)
Gets messages from a channel.
Pins a message in a channel.
Options
:reason- Audit log reason
Gets pinned messages in a channel, paginating automatically.
Returns message objects. Use pins/2 if you need the pinned_at timestamps
or want to drive the pagination yourself.
Options
:limit- maximum number of messages to return (default:infinity)
Examples
{:ok, msgs} = EDA.API.Message.pinned(channel_id)
{:ok, msgs} = EDA.API.Message.pinned(channel_id, limit: 10)
Gets one page of a channel's pins.
Returns Discord's raw envelope: %{"items" => [pin], "has_more" => boolean},
where each pin is %{"pinned_at" => iso8601, "message" => message}.
Options
:before- ISO8601 timestamp, get pins pinned before this (use thepinned_atof the last item of the previous page):limit- pins per page (1-50, default 50)
@spec purge( String.t() | integer(), keyword() ) :: {:ok, non_neg_integer()} | {:error, term()}
Purges messages from a channel with automatic chunking and 14-day filtering.
Options
:limit- max messages to purge (default 100, max:infinity):before- purge messages before this ID:after- purge messages after this ID:filter- predicatefn(message) -> booleanto select which messages to purge:filter_old- filter out messages older than 14 days (defaulttrue)
Examples
{:ok, count} = EDA.API.Message.purge(channel_id, limit: 200)
{:ok, count} = EDA.API.Message.purge(channel_id,
limit: 500,
filter: fn msg -> msg["author"]["id"] == user_id end
)
Replies to a message, automatically setting message_reference.
Accepts a message struct (with :channel_id and :id) or a raw map
(with "channel_id" and "id").
Examples
EDA.API.Message.reply(msg, "Got it!")
EDA.API.Message.reply(msg, content: "Reply with embed", embeds: [embed])
@spec stream( String.t() | integer(), keyword() ) :: Enumerable.t()
Returns a lazy Stream that yields messages from a channel, page by page.
Options
:before- start before this message ID:after- start after this message ID:per_page- messages per request (1-100, default 100)
Examples
EDA.API.Message.stream(channel_id) |> Stream.take(50) |> Enum.to_list()
EDA.API.Message.stream(channel_id) |> Enum.find(&(&1["author"]["id"] == user_id))
Unpins a message from a channel.
Options
:reason- Audit log reason