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

Copy Markdown View Source

REST API endpoints for Discord users.

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

Summary

Functions

Creates a DM channel with a user.

Gets a user by ID.

Lists the guilds the bot is in, as partial guild objects.

Leaves a guild. Discord then sends GUILD_DELETE for it.

Gets the current bot user.

Modifies the current bot user — its account-wide identity.

Streams every guild the bot is in, 200 per request, lazily.

Functions

create_dm(user_id)

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

Creates a DM channel with a user.

get(user_id)

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

Gets a user by ID.

guilds(opts \\ [])

@spec guilds(keyword()) :: {:ok, [map()]} | {:error, term()}

Lists the guilds the bot is in, as partial guild objects.

GET /users/@me/guilds. Returns at most 200 per call; stream_guilds/1 pages through them all.

Options

  • :before, :after — guild id cursors
  • :limit — 1–200, default 200
  • :with_counts — include approximate_member_count and approximate_presence_count
  • :shard — only the guilds of this shard, 0 to max_concurrency - 1. Required for a bot using large bot sharding: Discord answers 400 without it since September 2026

leave_guild(guild_id)

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

Leaves a guild. Discord then sends GUILD_DELETE for it.

DELETE /users/@me/guilds/{guild_id}. The bot cannot leave a guild it owns.

me()

@spec me() :: {:ok, map()} | {:error, term()}

Gets the current bot user.

modify_me(opts)

@spec modify_me(map() | keyword()) :: {:ok, map()} | {:error, term()}

Modifies the current bot user — its account-wide identity.

PATCH /users/@me, taking username, avatar and banner. A per-guild profile is set with EDA.API.Member.modify_me/2 instead, and overrides this one in that guild.

avatar and banner are image data: a path or raw bytes is converted to a data URI for you, and nil clears the field. See EDA.ImageData.

EDA.API.User.modify_me(%{username: "EDA", avatar: "priv/avatar.png"})

Changing the username may randomise the discriminator, and Discord rate-limits it heavily — this is not a call to make on a schedule.

stream_guilds(opts \\ [])

@spec stream_guilds(keyword()) :: Enumerable.t()

Streams every guild the bot is in, 200 per request, lazily.

Takes the options of guilds/1 except :before, :after and :limit.

EDA.API.User.stream_guilds(with_counts: true) |> Enum.count()