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
@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
@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.
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.
Deletes an invite.
Options
:reason- audit log reason
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)
@spec flag_guest_invite() :: integer()
This invite is a guest invite (1 <<< 0).
@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.
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
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
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
@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.
@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
Lists the user ids allowed to accept this invite.
Names the invite's kind.
Examples
iex> EDA.Invite.type(%EDA.Invite{type: 0})
:guild
iex> EDA.Invite.type(%EDA.Invite{type: nil})
:guild
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"