View Source Nostrum.Api.Self (Nostrum v0.10.4)

Module for interacting with the current user.

See the endpoints containing @me in the Discord API documentation: https://discord.com/developers/docs/resources/user

Summary

Functions

Gets the bot's OAuth2 application info.

Gets a list of user connections.

Gets a list of our user's DM channels.

Gets info on the current user.

Gets a list of guilds the user is currently in.

Changes the username or avatar of the current user.

Updates the status of the bot for a certain shard.

Updates the status of the bot for all shards.

Joins, moves, or disconnects the bot from a voice channel.

Functions

Link to this function

application_information()

View Source (since 0.10.1)
@spec application_information() :: Nostrum.Api.error() | {:ok, map()}

Gets the bot's OAuth2 application info.

Example

Nostrum.Api.Self.application_information
{:ok,
%{
  bot_public: false,
  bot_require_code_grant: false,
  description: "Test",
  icon: nil,
  id: "172150183260323840",
  name: "Baba O-Riley",
  owner: %{
    avatar: nil,
    discriminator: "0042",
    id: "172150183260323840",
    username: "i own a bot"
  },
}}
Link to this function

connections()

View Source (since 0.10.1)
@spec connections() :: Nostrum.Api.error() | {:ok, list()}

Gets a list of user connections.

Gets a list of our user's DM channels.

If successful, returns {:ok, dm_channels}. Otherwise, returns a Nostrum.Api.error/0.

Examples

Nostrum.Api.Self.dms()
{:ok, [%Nostrum.Struct.Channel{type: 1} | _]}
@spec get() :: Nostrum.Api.error() | {:ok, Nostrum.Struct.User.t()}

Gets info on the current user.

If nostrum's caching is enabled, it is recommended to use Me.get/0 instead of this function. This is because sending out an API request is much slower than pulling from our cache.

If the request is successful, this function returns {:ok, user}, where user is nostrum's Nostrum.Struct.User. Otherwise, returns {:error, reason}.

Link to this function

guilds(options \\ [])

View Source (since 0.10.1)

Gets a list of guilds the user is currently in.

This endpoint requires the guilds OAuth2 scope.

If successful, returns {:ok, guilds}. Otherwise, returns a Nostrum.Api.error/0.

Options

Examples

iex> Nostrum.Api.Self.guilds(limit: 1)
{:ok, [%Nostrum.Struct.Guild{}]}
Link to this function

modify(options)

View Source (since 0.10.1)

Changes the username or avatar of the current user.

Options

  • :username (string) - new username
  • :avatar (string) - the user's avatar as avatar data

Examples

Nostrum.Api.Self.modify(avatar: "data:image/jpeg;base64,YXl5IGJieSB1IGx1a2luIDQgc3VtIGZ1az8=")
Link to this function

update_shard_status(pid, status, game, type \\ 0, stream \\ nil)

View Source (since 0.10.1)
@spec update_shard_status(
  pid(),
  Nostrum.Api.status(),
  String.t(),
  integer(),
  String.t() | nil
) :: :ok

Updates the status of the bot for a certain shard.

Parameters

  • pid - Pid of the shard.
  • status - Status of the bot.
  • game - The 'playing' text of the bot. Empty will clear.
  • type - The type of status to show. 0 (Playing) | 1 (Streaming) | 2 (Listening) | 3 (Watching)

  • stream - URL of twitch.tv stream
Link to this function

update_status(status, game, type \\ 0, stream \\ nil)

View Source (since 0.10.1)
@spec update_status(Nostrum.Api.status(), String.t(), integer(), String.t() | nil) ::
  :ok

Updates the status of the bot for all shards.

See update_shard_status/5 for usage.

Link to this function

update_voice_state(guild_id, channel_id, self_mute \\ false, self_deaf \\ false)

View Source (since 0.10.1)
@spec update_voice_state(
  Nostrum.Struct.Guild.id(),
  Nostrum.Struct.Channel.id() | nil,
  boolean(),
  boolean()
) :: no_return() | :ok

Joins, moves, or disconnects the bot from a voice channel.

The correct shard to send the update to will be inferred from the guild_id. If a corresponding guild_id is not found a cache error will be raised.

To disconnect from a channel, channel_id should be set to nil.