EDA.Channel (EDA v0.4.0)

Copy Markdown View Source

Represents a Discord channel.

Channel types

ConstantValueDescription
type_guild_text/00Text channel in a guild
type_dm/01Direct message
type_guild_voice/02Voice channel in a guild
type_group_dm/03Group DM
type_guild_category/04Category
type_guild_news/05News / announcement channel
type_guild_news_thread/010Thread in a news channel
type_guild_public_thread/011Public thread
type_guild_private_thread/012Private thread
type_guild_stage_voice/013Stage voice channel
type_guild_forum/015Forum channel
type_guild_media/016Media channel

Forum layout types

ConstantValueDescription
layout_not_set/00Not set
layout_list_view/01List view
layout_gallery_view/02Gallery view

Sort order types

ConstantValueDescription
sort_latest_activity/00Latest activity
sort_creation_date/01Creation date

Summary

Types

A channel flag name.

t()

Functions

Every flag name EDA knows about.

Applies a changeset to a channel. 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.

Deletes a channel.

Fetches a channel by ID. Checks cache first, falls back to REST.

Fetches a channel by ID. Raises on error.

Hides embedded media download options; media channels only (1 <<< 15).

Returns the set flags as a list of names, ignoring bits EDA does not know.

The channel's metadata is obfuscated because the bot cannot view it (1 <<< 17).

Thread pinned in its parent forum or media channel (1 <<< 1).

Threads in this forum or media channel require a tag (1 <<< 4).

The channel requires opt-in viewing (1 <<< 21).

Returns true if the channel is a forum channel (type 15).

Returns true if the given flag is set.

Returns 2 — Gallery view layout.

Returns 1 — List view layout.

Returns 0 — Forum layout not set.

Returns true if the channel is a media channel (type 16).

Modifies a channel. Accepts a struct or ID, a map of changes, and options.

Returns true if Discord has obfuscated this channel because the bot cannot view it.

The name Discord substitutes for an obfuscated channel.

Sends a message to a channel. Returns a %EDA.Message{} struct.

Sets a voice channel's status (up to 500 characters, or nil to clear it).

Returns 1 — Sort by creation date.

Returns 0 — Sort by latest activity.

Returns true if the channel is a thread (types 10, 11, 12).

Returns 1 — Direct message.

Returns 3 — Group DM.

Returns 4 — Guild category.

Returns 15 — Forum channel.

Returns 16 — Media channel.

Returns 5 — Guild news/announcement channel.

Returns 10 — Thread in a news channel.

Returns 12 — Private thread.

Returns 11 — Public thread.

Returns 13 — Stage voice channel.

Returns 0 — Guild text channel.

Returns 2 — Guild voice channel.

Types

flag()

@type flag() ::
  :pinned | :require_tag | :hide_media_download_options | :obfuscated | :spoiler

A channel flag name.

t()

@type t() :: %EDA.Channel{
  applied_tags: [String.t()] | nil,
  available_tags: [EDA.ForumTag.t()] | nil,
  bitrate: integer() | nil,
  default_auto_archive_duration: integer() | nil,
  default_forum_layout: integer() | nil,
  default_reaction_emoji: map() | nil,
  default_sort_order: integer() | nil,
  default_thread_rate_limit_per_user: integer() | nil,
  flags: integer() | nil,
  guild_id: String.t() | nil,
  id: String.t() | nil,
  last_message_id: String.t() | nil,
  member_count: integer() | nil,
  message_count: integer() | nil,
  name: String.t() | nil,
  nsfw: boolean() | nil,
  owner_id: String.t() | nil,
  parent_id: String.t() | nil,
  permission_overwrites: [EDA.PermissionOverwrite.t()] | nil,
  position: integer() | nil,
  rate_limit_per_user: integer() | nil,
  status: String.t() | nil,
  thread_metadata: map() | nil,
  topic: String.t() | nil,
  total_message_sent: integer() | nil,
  type: integer() | nil,
  user_limit: integer() | nil
}

Functions

all_flags()

@spec all_flags() :: [flag()]

Every flag name EDA knows about.

apply_changeset(changeset, opts \\ [])

@spec apply_changeset(
  EDA.Entity.Changeset.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}

Applies a changeset to a channel. No-op if the changeset has no changes.

Options

  • :reason - Audit log reason

change(cs, key, value)

Adds a change to an existing changeset for this entity.

changeset(entity)

@spec changeset(t()) :: EDA.Entity.Changeset.t()

Creates a changeset for batching mutations to this entity.

delete(channel, opts \\ [])

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

Deletes a channel.

Options

  • :reason - Audit log reason

fetch(channel_id)

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

Fetches a channel by ID. Checks cache first, falls back to REST.

fetch!(channel_id)

@spec fetch!(t() | String.t() | integer()) :: t()

Fetches a channel by ID. Raises on error.

flag_hide_media_download_options()

@spec flag_hide_media_download_options() :: integer()

Hides embedded media download options; media channels only (1 <<< 15).

flag_list(channel)

@spec flag_list(t() | map() | integer() | nil) :: [flag()]

Returns the set flags as a list of names, ignoring bits EDA does not know.

Examples

iex> EDA.Channel.flag_list(%EDA.Channel{flags: (1 <<< 17) + (1 <<< 1)})
[:obfuscated, :pinned]

iex> EDA.Channel.flag_list(nil)
[]

flag_obfuscated()

@spec flag_obfuscated() :: integer()

The channel's metadata is obfuscated because the bot cannot view it (1 <<< 17).

flag_pinned()

@spec flag_pinned() :: integer()

Thread pinned in its parent forum or media channel (1 <<< 1).

flag_require_tag()

@spec flag_require_tag() :: integer()

Threads in this forum or media channel require a tag (1 <<< 4).

flag_spoiler()

@spec flag_spoiler() :: integer()

The channel requires opt-in viewing (1 <<< 21).

forum?(channel)

@spec forum?(t()) :: boolean()

Returns true if the channel is a forum channel (type 15).

Examples

iex> EDA.Channel.forum?(%EDA.Channel{type: 15})
true

iex> EDA.Channel.forum?(%EDA.Channel{type: 0})
false

from_raw(raw)

@spec from_raw(map()) :: t()

has_flag?(channel, flag)

@spec has_flag?(t() | map() | integer() | nil, flag()) :: boolean()

Returns true if the given flag is set.

Accepts a t/0, a raw channel map as the cache stores it, a bitfield, or nil.

Examples

iex> EDA.Channel.has_flag?(%EDA.Channel{flags: 1 <<< 17}, :obfuscated)
true

iex> EDA.Channel.has_flag?(%{"flags" => 0}, :obfuscated)
false

iex> EDA.Channel.has_flag?(nil, :obfuscated)
false

layout_list_view()

Returns 1 — List view layout.

layout_not_set()

Returns 0 — Forum layout not set.

media?(channel)

@spec media?(t()) :: boolean()

Returns true if the channel is a media channel (type 16).

Examples

iex> EDA.Channel.media?(%EDA.Channel{type: 16})
true

iex> EDA.Channel.media?(%EDA.Channel{type: 0})
false

modify(channel, payload, opts \\ [])

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

Modifies a channel. Accepts a struct or ID, a map of changes, and options.

Options

  • :reason - Audit log reason

obfuscated?(channel)

@spec obfuscated?(t() | map() | integer() | nil) :: boolean()

Returns true if Discord has obfuscated this channel because the bot cannot view it.

Obfuscated channels are still dispatched over the gateway, but their metadata is redacted: name becomes ___hidden___, sensitive fields are nulled, and permission_overwrites holds a single overwrite denying VIEW_CHANNEL to the guild's @everyone role. Treat them as "exists but invisible" — in particular do not compute permissions from those overwrites, and consider filtering them out of channel listings shown to users.

Mandatory for every bot from 2026-11-16; before then it is opt-in via config :eda, capabilities: [:channel_obfuscation] (see EDA.Gateway.Capabilities).

Examples

iex> EDA.Channel.obfuscated?(%EDA.Channel{flags: 1 <<< 17})
true

iex> EDA.Channel.obfuscated?(%EDA.Channel{flags: 0})
false

iex> EDA.Channel.obfuscated?(%{"flags" => 1 <<< 17})
true

iex> EDA.Channel.obfuscated?(nil)
false

obfuscated_name()

@spec obfuscated_name() :: String.t()

The name Discord substitutes for an obfuscated channel.

Examples

iex> EDA.Channel.obfuscated_name()
"___hidden___"

send_message(channel_id, content)

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

Sends a message to a channel. Returns a %EDA.Message{} struct.

set_voice_status(channel, status, opts \\ [])

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

Sets a voice channel's status (up to 500 characters, or nil to clear it).

Accepts a channel struct or ID.

Options

  • :reason - Audit log reason

sort_creation_date()

Returns 1 — Sort by creation date.

sort_latest_activity()

Returns 0 — Sort by latest activity.

thread?(channel)

@spec thread?(t()) :: boolean()

Returns true if the channel is a thread (types 10, 11, 12).

Examples

iex> EDA.Channel.thread?(%EDA.Channel{type: 11})
true

iex> EDA.Channel.thread?(%EDA.Channel{type: 0})
false

type_dm()

Returns 1 — Direct message.

type_group_dm()

Returns 3 — Group DM.

type_guild_category()

Returns 4 — Guild category.

type_guild_forum()

Returns 15 — Forum channel.

type_guild_media()

Returns 16 — Media channel.

type_guild_news()

Returns 5 — Guild news/announcement channel.

type_guild_news_thread()

Returns 10 — Thread in a news channel.

type_guild_private_thread()

Returns 12 — Private thread.

type_guild_public_thread()

Returns 11 — Public thread.

type_guild_stage_voice()

Returns 13 — Stage voice channel.

type_guild_text()

Returns 0 — Guild text channel.

type_guild_voice()

Returns 2 — Guild voice channel.