Represents a Discord message.
Summary
Functions
Applies a changeset to a message. No-op if the changeset has no changes.
Adds a change to an existing changeset for this entity.
Creates a changeset for batching mutations to this entity.
Publishes a message from an announcement channel to every channel following it, and returns it
updated. See EDA.API.Message.crosspost/2 for the permissions.
Deletes a message.
Edits a message. Accepts a raw payload map or a keyword list of options.
Fetches a message by channel ID and message ID. No cache (messages are not cached).
Pins a message in its channel.
Adds a reaction to a message.
Replies to a message. Returns a %EDA.Message{} struct.
Searches a guild's message history, returning structs.
Unpins a message from its channel.
Types
@type t() :: %EDA.Message{ attachments: [EDA.Attachment.t()] | nil, author: EDA.User.t() | nil, channel_id: String.t() | nil, components: [map()] | nil, content: String.t() | nil, edited_timestamp: String.t() | nil, embeds: [map()] | nil, guild_id: String.t() | nil, id: String.t() | nil, member: EDA.Member.t() | nil, mention_everyone: boolean() | nil, mention_roles: [String.t()] | nil, mentions: [EDA.User.t()] | nil, message_reference: map() | nil, pinned: boolean() | nil, poll: EDA.Poll.t() | nil, reactions: [EDA.Reaction.t()] | nil, referenced_message: t() | nil, sticker_items: [map()] | nil, timestamp: String.t() | nil, tts: boolean() | nil, type: integer() | nil }
Functions
@spec apply_changeset( EDA.Entity.Changeset.t(), keyword() ) :: {:ok, t()} | {:error, term()}
Applies a changeset to a message. No-op if the changeset has no changes.
@spec change(EDA.Entity.Changeset.t(), atom(), term()) :: EDA.Entity.Changeset.t()
Adds a change to an existing changeset for this entity.
@spec changeset(t()) :: EDA.Entity.Changeset.t()
Creates a changeset for batching mutations to this entity.
Publishes a message from an announcement channel to every channel following it, and returns it
updated. See EDA.API.Message.crosspost/2 for the permissions.
Deletes a message.
Options
:reason- Audit log reason
Edits a message. Accepts a raw payload map or a keyword list of options.
The keyword form supports everything EDA.API.Message.edit/3 does, including :files
and :attachments.
Attachments are replaced, not merged
Discord deletes any attachment missing from the attachments array, so uploading a file
to a message that already has some wipes them unless they are named. Since the struct
already carries them, attachments: :keep says "everything this message has now", with
no extra request:
EDA.Message.edit(message,
content: "one more",
attachments: :keep,
files: [EDA.File.from_path("extra.png")]
)Pass a list instead to keep only part of them, or to change what an attachment says —
see EDA.Attachment.keep/2:
EDA.Message.edit(message,
attachments: [EDA.Attachment.keep(hd(message.attachments), is_spoiler: true)]
)
@spec fetch_message(String.t() | integer(), String.t() | integer()) :: {:ok, t()} | {:error, term()}
Fetches a message by channel ID and message ID. No cache (messages are not cached).
Pins a message in its channel.
Options
:reason- Audit log reason
@spec react(t(), String.t() | EDA.Emoji.t()) :: :ok | {:error, term()}
Adds a reaction to a message.
The emoji parameter accepts a string ("👍" or "name:id") or an EDA.Emoji struct.
Replies to a message. Returns a %EDA.Message{} struct.
@spec search( String.t() | integer(), keyword() ) :: {:ok, %{ results: [t()], groups: [[t()]], total_results: integer(), indexing?: boolean() }} | {:error, term()}
Searches a guild's message history, returning structs.
Takes the same options as EDA.API.Message.search/2, and flattens the nesting that
endpoint returns:
{:ok, found} = EDA.Message.search(guild_id, content: "deploy", has: [:link])
found.total_results #=> 1034 (approximate, see below)
found.results #=> [%EDA.Message{}, ...] — the matches themselves
found.groups #=> [[%EDA.Message{}], ...] — each match with its neighbours
found.indexing? #=> false:results is what you almost always want. :groups keeps the surrounding messages
Discord sends for context; a group is usually one message, but that is not promised, and
the match inside it is the one :results picked.
:total_results is Discord's own count and is approximate while messages are being
created or deleted. :indexing? is true while Discord is still walking the guild's older
history, which means more results may appear later for the same query.
Requires READ_MESSAGE_HISTORY and the MESSAGE_CONTENT intent. A guild that is not
indexed yet answers {:error, {:index_pending, retry_after_seconds}}.
Unpins a message from its channel.
Options
:reason- Audit log reason