EDA.API.Ban (EDA v0.3.0)

Copy Markdown View Source

REST API endpoints for Discord guild bans.

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

Summary

Functions

Bans up to 200 users from a guild in a single request.

Bans a user from a guild.

Gets a specific ban for a guild.

Gets bans for a guild.

Unbans a user from a guild.

Returns a lazy Stream that paginates through all bans in a guild.

Functions

bulk(guild_id, user_ids, opts \\ [])

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

Bans up to 200 users from a guild in a single request.

Options

  • :delete_message_seconds - Seconds of messages to delete (0-604800)

Returns {:ok, %{"banned_users" => [...], "failed_users" => [...]}}.

create(guild_id, user_id, opts \\ [])

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

Bans a user from a guild.

Options

  • :delete_message_seconds — seconds of message history to delete (0-604800)
  • :reason — audit log reason (sent as X-Audit-Log-Reason header)

get(guild_id, user_id)

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

Gets a specific ban for a guild.

list(guild_id, opts \\ [])

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

Gets bans for a guild.

remove(guild_id, user_id)

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

Unbans a user from a guild.

stream(guild_id, opts \\ [])

@spec stream(
  String.t() | integer(),
  keyword()
) :: Enumerable.t()

Returns a lazy Stream that paginates through all bans in a guild.

Options

  • :direction — :before or :after (default :before)
  • :per_page — bans per request (1-1000, default 1000)
  • :before — start before this user ID
  • :after — start after this user ID

Examples

EDA.API.Ban.stream(guild_id) |> Enum.to_list()
EDA.API.Ban.stream(guild_id, per_page: 100) |> Stream.take(50) |> Enum.to_list()