Noizu.Discord.Client (Noizu.Discord v0.1.0)

Copy Markdown View Source

Explicit connection configuration, passed as the first argument to every call.

client = Noizu.Discord.Client.new(token: System.fetch_env!("DISCORD_BOT_TOKEN"))
{:ok, me} = Noizu.Discord.Users.me(client)

Token precedence

opts[:token] -> Application.get_env(:noizu_discord, :client)[:token] -> the DISCORD_BOT_TOKEN environment variable. The token is sent as Authorization: Bot <token>. It may be nil at construction; requests that need it fail with {:error, %Noizu.Discord.Error{tag: :config}}.

Other options follow the same opts -> app env -> default precedence.

Options

  • :token — bot token (without the Bot prefix).
  • :base_url — API root. Default: https://discord.com/api/v10.
  • :user_agent — User-Agent header. Default (per Discord's UA rule): DiscordBot (https://github.com/noizu-labs-sdks/elixir-discord, 0.1.0).
  • :req_options — keyword options merged into every Req.request/1 call (e.g. plug:, receive_timeout:). The library's own method/url/auth options win.
  • :retry — keyword: :max_attempts (total attempts, default 3; 1 disables retrying), :base_backoff_ms (default 500, used when the server sends no delay hint), :max_delay_ms (clamp for server-supplied delays, default 30_000), :sleep_fn (default &Process.sleep/1; test hook).

The Inspect implementation redacts the token.

Summary

Functions

Default API root (https://discord.com/api/v10).

Default User-Agent header value.

Builds a client struct. See the module doc for option details.

Types

t()

@type t() :: %Noizu.Discord.Client{
  base_url: String.t(),
  req_options: keyword(),
  retry: keyword(),
  token: String.t() | nil,
  user_agent: String.t()
}

Functions

default_base_url()

@spec default_base_url() :: String.t()

Default API root (https://discord.com/api/v10).

default_user_agent()

@spec default_user_agent() :: String.t()

Default User-Agent header value.

new(opts \\ [])

@spec new(keyword()) :: t()

Builds a client struct. See the module doc for option details.