EDA.Invite (EDA v0.5.0-beta.2)

Copy Markdown View Source

Represents a Discord invite.

The same struct covers both shapes Discord sends. The REST invite object nests guild and channel objects; the INVITE_CREATE gateway event sends flat guild_id and channel_id instead. guild_id and channel_id are filled in from the nested objects when Discord did not send them, so they can be read either way.

Summary

Functions

Adds a change to an existing changeset for this entity.

Creates a changeset for batching mutations to this entity.

Creates an invite for a channel. Returns a t/0.

Deletes an invite.

Fetches an invite by code. No cache — invites are not cached.

This invite is a guest invite (1 <<< 0).

This invite is restricted to a list of target users (1 <<< 4).

Returns true if this is a guest invite.

Returns true if this invite is restricted to a list of target users.

Returns true if the invite never expires.

Replaces the user ids allowed to accept this invite.

Names what a voice channel invite points at, or nil for an ordinary invite.

Lists the user ids allowed to accept this invite.

Names the invite's kind.

The invite's URL.

Types

t()

@type t() :: %EDA.Invite{
  approximate_member_count: integer() | nil,
  approximate_presence_count: integer() | nil,
  channel: map() | nil,
  channel_id: String.t() | nil,
  code: String.t() | nil,
  created_at: String.t() | nil,
  expires_at: String.t() | nil,
  flags: integer() | nil,
  guild: map() | nil,
  guild_id: String.t() | nil,
  guild_scheduled_event: map() | nil,
  inviter: EDA.User.t() | nil,
  max_age: integer() | nil,
  max_uses: integer() | nil,
  roles: [EDA.Role.t()] | nil,
  target_application: map() | nil,
  target_type: integer() | nil,
  target_user: EDA.User.t() | nil,
  temporary: boolean() | nil,
  type: integer() | nil,
  uses: integer() | nil
}

Functions

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.

create(channel_id, opts \\ [])

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

Creates an invite for a channel. Returns a t/0.

Takes the same options as EDA.API.Invite.create/2, including :role_ids and :target_users.

delete(invite, opts \\ [])

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

Deletes an invite.

Options

  • :reason - audit log reason

fetch_invite(invite_code, opts \\ [])

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

Fetches an invite by code. No cache — invites are not cached.

Named fetch_invite/2 rather than fetch/2 because Access.fetch/2 owns that arity.

Options

  • :with_counts - include the approximate member and presence counts
  • :guild_scheduled_event_id - include that event

Examples

EDA.Invite.fetch_invite("abc123", with_counts: true)

flag_guest_invite()

@spec flag_guest_invite() :: integer()

This invite is a guest invite (1 <<< 0).

flag_has_target_users()

@spec flag_has_target_users() :: integer()

This invite is restricted to a list of target users (1 <<< 4).

Discord does not document this bit. It was observed on 2026-09-19: creating an invite with target_users returns flags: 16, and an invite without them carries no flags key at all. Treat it as a hint rather than a contract — EDA.API.Invite.target_users/1 is the authoritative answer.

from_raw(raw)

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

guest_invite?(bitfield)

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

Returns true if this is a guest invite.

Accepts a t/0, a raw invite map, a bitfield, or nil.

Examples

iex> EDA.Invite.guest_invite?(%EDA.Invite{flags: 1})
true

iex> EDA.Invite.guest_invite?(nil)
false

has_target_users?(bitfield)

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

Returns true if this invite is restricted to a list of target users.

Reads the undocumented bit described on flag_has_target_users/0, so a false here is weaker than a {:ok, []} from EDA.API.Invite.target_users/1.

Examples

iex> EDA.Invite.has_target_users?(%EDA.Invite{flags: 16})
true

iex> EDA.Invite.has_target_users?(%EDA.Invite{flags: nil})
false

permanent?(raw)

@spec permanent?(t() | map()) :: boolean()

Returns true if the invite never expires.

Discord expresses that as max_age: 0, and as a null expires_at on the REST object.

Examples

iex> EDA.Invite.permanent?(%EDA.Invite{max_age: 0})
true

iex> EDA.Invite.permanent?(%EDA.Invite{max_age: 3600})
false

set_target_users(invite_code, users)

@spec set_target_users(t() | String.t(), [String.t() | integer()] | binary()) ::
  {:ok, map()} | {:error, term()}

Replaces the user ids allowed to accept this invite.

Applied asynchronously — see EDA.API.Invite.target_users_job_status/1.

target_type(value)

@spec target_type(t() | map() | integer() | nil) ::
  :stream | :embedded_application | :unknown | nil

Names what a voice channel invite points at, or nil for an ordinary invite.

Examples

iex> EDA.Invite.target_type(%EDA.Invite{target_type: 1})
:stream

iex> EDA.Invite.target_type(%EDA.Invite{target_type: nil})
nil

target_users(invite_code)

@spec target_users(t() | String.t()) :: {:ok, [String.t()]} | {:error, term()}

Lists the user ids allowed to accept this invite.

See EDA.API.Invite.target_users/1.

type(value)

@spec type(t() | map() | integer() | nil) :: :guild | :group_dm | :friend | :unknown

Names the invite's kind.

Examples

iex> EDA.Invite.type(%EDA.Invite{type: 0})
:guild

iex> EDA.Invite.type(%EDA.Invite{type: nil})
:guild

url(code)

@spec url(t() | map() | String.t()) :: String.t() | nil

The invite's URL.

Examples

iex> EDA.Invite.url(%EDA.Invite{code: "abc123"})
"https://discord.gg/abc123"

iex> EDA.Invite.url("abc123")
"https://discord.gg/abc123"