Nostrum.Api.Self (nostrum v0.11.0-dev)
View SourceModule 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
@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"
},
}}
@spec connections() :: Nostrum.Api.error() | {:ok, list()}
Gets a list of user connections.
@spec dms() :: Nostrum.Api.error() | {:ok, [Nostrum.Struct.Channel.dm_channel()]}
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}
.
@spec guilds(Nostrum.Api.options()) :: Nostrum.Api.error() | {:ok, [Nostrum.Struct.Guild.user_guild()]}
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
:before
(Nostrum.Snowflake.t/0
) - get guilds before this guild ID:after
(Nostrum.Snowflake.t/0
) - get guilds after this guild ID:limit
(integer) - max number of guilds to return (1-100)
Examples
iex> Nostrum.Api.Self.guilds(limit: 1)
{:ok, [%Nostrum.Struct.Guild{}]}
@spec modify(Nostrum.Api.options()) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.User.t()}
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=")
@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.
@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.
@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
.