Nostrum.Api.Self (nostrum v0.11.0-dev)

View Source

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

application_information()

(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"
  },
}}

connections()

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

Gets a list of user connections.

dms()

(since 0.10.1)

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} | _]}

get()

(since 0.10.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}.

guilds(options \\ [])

(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{}]}

modify(options)

(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=")

update_shard_status(pid, status, activity)

(since 0.10.1)
@spec update_shard_status(pid(), Nostrum.Api.status(), Nostrum.Api.activity()) :: :ok

Updates the status of the bot for a certain shard.

Please see the types t:Api.status/0 and t:Api.activity/0 for more information.

update_status(status, activity)

(since 0.10.1)
@spec update_status(Nostrum.Api.status(), Nostrum.Api.activity()) :: :ok

Updates the status of the bot for all shards.

See update_shard_status/3 for usage.

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

(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.