EDA.Channel (EDA v0.3.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

Functions

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.

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

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.

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

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

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.

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()

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

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.