EDA.API.Guild (EDA v0.5.0-beta.2)

Copy Markdown View Source

REST API endpoints for Discord guilds.

All functions return {:ok, result} or {:error, reason}.

Summary

Functions

Gets the audit log for a guild.

Gets channels in a guild.

Deletes a guild integration, with its webhooks — and kicks its bot, if it has one. Requires MANAGE_GUILD.

Gets a guild by ID.

Lists a guild's integrations — Twitch, YouTube, and bot or OAuth2 applications. Requires MANAGE_GUILD. Discord returns at most 50; EDA.Integration.from_raw/1 parses each.

Gets invites for a guild.

Pauses invites or direct messages in a guild during a raid, for up to 24 hours. Requires MANAGE_GUILD.

Replaces a guild's onboarding. Requires MANAGE_GUILD and MANAGE_ROLES.

Modifies a guild's welcome screen. Requires MANAGE_GUILD. Every field is optional.

Modifies a guild's widget settings. Requires MANAGE_GUILD.

Gets a guild's onboarding: its prompts, default channels, and whether it is enabled.

Gets a guild's preview: name, icon, emojis, stickers, features and approximate counts. For a guild the bot is not in, the guild must be discoverable.

Begins a guild prune. This kicks members.

Gets the number of members that would be pruned.

Gets a guild's vanity invite and how many times it was used, %{"code" => ..., "uses" => ...}. Requires MANAGE_GUILD and the VANITY_URL feature. The code alone is on the guild object as vanity_url_code; this route is the only way to the use count.

Lists the voice regions available to a guild, VIP ones included. See EDA.API.Voice.regions/0.

Gets a guild's welcome screen: its description and the channels it recommends. Needs MANAGE_GUILD while the welcome screen is disabled.

Gets a guild's public widget: its name, online members and instant invite. Needs the widget to be enabled, and nothing else — no permission, no authentication.

The URL of a guild's widget image, a PNG anyone can load while the widget is enabled — for a website or a README. Builds the URL; nothing is fetched.

Gets a guild's widget settings, %{"enabled" => ..., "channel_id" => ...}. Requires MANAGE_GUILD.

Functions

audit_log(guild_id, opts \\ [])

@spec audit_log(
  String.t() | integer(),
  keyword()
) ::
  {:ok, %{entries: [EDA.AuditLog.Entry.t()], users: [map()], webhooks: [map()]}}
  | {:error, term()}

Gets the audit log for a guild.

Options

  • :user_id - Filter by user who performed the action
  • :action_type - Filter by action type (integer or atom via EDA.AuditLog.action_type/1)
  • :before - Get entries before this entry ID
  • :after - Get entries after this entry ID
  • :limit - Number of entries (1-100, default 50)

channels(guild_id)

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

Gets channels in a guild.

delete_integration(guild_id, integration_id, opts \\ [])

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

Deletes a guild integration, with its webhooks — and kicks its bot, if it has one. Requires MANAGE_GUILD.

Options

  • :reason — audit log reason

get(guild_id)

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

Gets a guild by ID.

integrations(guild_id)

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

Lists a guild's integrations — Twitch, YouTube, and bot or OAuth2 applications. Requires MANAGE_GUILD. Discord returns at most 50; EDA.Integration.from_raw/1 parses each.

invites(guild_id)

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

Gets invites for a guild.

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

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

Modifies a guild.

modify_incident_actions(guild_id, opts)

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

Pauses invites or direct messages in a guild during a raid, for up to 24 hours. Requires MANAGE_GUILD.

Options

  • :invites_disabled_until — a DateTime (or ISO8601 string) at most 24 hours ahead, or nil to allow invites again
  • :dms_disabled_until — the same, for direct messages between members

Returns the guild's incidents data.

until = DateTime.add(DateTime.utc_now(), 3600)
EDA.API.Guild.modify_incident_actions(guild_id, invites_disabled_until: until)

modify_onboarding(guild_id, opts)

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

Replaces a guild's onboarding. Requires MANAGE_GUILD and MANAGE_ROLES.

PUT /guilds/{guild_id}/onboarding. Every field is optional, but :prompts, when given, is the complete list: a prompt left out is deleted. EDA.Onboarding.save/2 is the safe way to change one prompt among several.

Options

  • :prompts — EDA.Onboarding.Prompt structs or raw prompt maps. An option's emoji is sent as emoji_id / emoji_name / emoji_animated whichever form it came in: Discord ignores the emoji object it returns, so sending that back would clear the emoji
  • :default_channel_ids — channels every member joins
  • :enabled — enabling needs at least 7 default channels, 5 of them open to @everyone
  • :mode — :default or :advanced
  • :reason — audit log reason

modify_welcome_screen(guild_id, opts)

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

Modifies a guild's welcome screen. Requires MANAGE_GUILD. Every field is optional.

Options

  • :enabled — whether the welcome screen is shown
  • :description — the server description it shows
  • :welcome_channels — the channels it recommends, each %{channel_id: ..., description: ..., emoji_id: ..., emoji_name: ...}
  • :reason — audit log reason

modify_widget(guild_id, opts)

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

Modifies a guild's widget settings. Requires MANAGE_GUILD.

Options

  • :enabled — whether the widget is on
  • :channel_id — the channel its invite leads to, or nil
  • :reason — audit log reason

onboarding(guild_id)

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

Gets a guild's onboarding: its prompts, default channels, and whether it is enabled.

GET /guilds/{guild_id}/onboarding. EDA.Onboarding.fetch/1 returns it as a struct.

preview(guild_id)

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

Gets a guild's preview: name, icon, emojis, stickers, features and approximate counts. For a guild the bot is not in, the guild must be discoverable.

prune(guild_id, opts)

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

Begins a guild prune. This kicks members.

Requires MANAGE_GUILD and KICK_MEMBERS — or ADMINISTRATOR when the guild has the PRUNE_REQUIRES_ADMIN feature, which its owner can turn on.

Options

  • :days - inactivity threshold, 1–30, default 7
  • :compute_prune_count - whether the response reports how many were removed. Discord advises false on large guilds
  • :include_roles - role ids whose members are eligible; without it, members with any role are spared
  • :reason - audit log reason

Accepts a keyword list or a map. An option this endpoint does not define raises ArgumentError and nothing is sent: Discord ignores an unrecognised body field, so day: 30 would prune on the default 7 days — a destructive call doing more than it was asked.

prune_count(guild_id, opts \\ [])

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

Gets the number of members that would be pruned.

Requires MANAGE_GUILD and KICK_MEMBERS — or ADMINISTRATOR when the guild has the PRUNE_REQUIRES_ADMIN feature, which its owner can turn on.

vanity_url(guild_id)

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

Gets a guild's vanity invite and how many times it was used, %{"code" => ..., "uses" => ...}. Requires MANAGE_GUILD and the VANITY_URL feature. The code alone is on the guild object as vanity_url_code; this route is the only way to the use count.

voice_regions(guild_id)

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

Lists the voice regions available to a guild, VIP ones included. See EDA.API.Voice.regions/0.

welcome_screen(guild_id)

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

Gets a guild's welcome screen: its description and the channels it recommends. Needs MANAGE_GUILD while the welcome screen is disabled.

widget(guild_id)

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

Gets a guild's public widget: its name, online members and instant invite. Needs the widget to be enabled, and nothing else — no permission, no authentication.

widget_image_url(guild_id, style \\ :shield)

@spec widget_image_url(String.t() | integer(), atom()) :: String.t()

The URL of a guild's widget image, a PNG anyone can load while the widget is enabled — for a website or a README. Builds the URL; nothing is fetched.

style is one of :shield (the default), :banner1 to :banner4.

iex> EDA.API.Guild.widget_image_url("1", :banner2)
"https://discord.com/api/v10/guilds/1/widget.png?style=banner2"

widget_settings(guild_id)

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

Gets a guild's widget settings, %{"enabled" => ..., "channel_id" => ...}. Requires MANAGE_GUILD.