EDA.ForumTag (EDA v0.3.0)

Copy Markdown View Source

Represents a tag available in a Discord Forum or Media channel.

Forum tags can be applied to threads (posts) within a forum channel to help organize discussions. Each tag has a name, an optional emoji, and a moderated flag that restricts who can apply it.

Existing vs new tags

Tags returned from the Discord API have an id (snowflake string). Tags you create programmatically with new/2 have id: nil — Discord assigns the ID when the channel is updated with the new tag list.

Examples

# Parse a tag from Discord API data
tag = EDA.ForumTag.from_raw(%{
  "id" => "123456",
  "name" => "Resolved",
  "moderated" => true,
  "emoji_id" => nil,
  "emoji_name" => "✅"
})

# Create a new tag programmatically
tag = EDA.ForumTag.new("Bug Report", moderated: true, emoji: "🐛")

# Serialize for API (e.g. updating available_tags on a channel)
EDA.ForumTag.to_raw(tag)

Summary

Functions

Parses a forum tag from a raw Discord API map.

Creates a new forum tag struct (without an ID).

Serializes a forum tag for the Discord API.

Types

t()

@type t() :: %EDA.ForumTag{
  emoji_id: String.t() | nil,
  emoji_name: String.t() | nil,
  id: String.t() | nil,
  moderated: boolean(),
  name: String.t()
}

Functions

from_raw(raw)

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

Parses a forum tag from a raw Discord API map.

Examples

iex> EDA.ForumTag.from_raw(%{"id" => "1", "name" => "Bug", "moderated" => false, "emoji_id" => nil, "emoji_name" => "🐛"})
%EDA.ForumTag{id: "1", name: "Bug", moderated: false, emoji_id: nil, emoji_name: "🐛"}

new(name, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: t()

Creates a new forum tag struct (without an ID).

Options

  • :moderated - if true, only users with MANAGE_THREADS can apply this tag. Defaults to false.
  • :emoji - an EDA.Emoji struct or a unicode string (e.g. "🐛").

Examples

iex> EDA.ForumTag.new("Help")
%EDA.ForumTag{name: "Help", moderated: false}

iex> EDA.ForumTag.new("Bug", moderated: true, emoji: "🐛")
%EDA.ForumTag{name: "Bug", moderated: true, emoji_name: "🐛"}

iex> EDA.ForumTag.new("Cool", emoji: %EDA.Emoji{id: "99", name: "cool"})
%EDA.ForumTag{name: "Cool", moderated: false, emoji_id: "99", emoji_name: "cool"}

to_raw(tag)

@spec to_raw(t()) :: map()

Serializes a forum tag for the Discord API.

Omits keys with nil values so Discord doesn't receive explicit nulls.

Examples

iex> tag = %EDA.ForumTag{id: "1", name: "Bug", moderated: false, emoji_name: "🐛"}
iex> EDA.ForumTag.to_raw(tag)
%{"id" => "1", "name" => "Bug", "moderated" => false, "emoji_name" => "🐛"}