Discord Social SDK
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
discordpp::UserHandle Class Reference

Detailed Description

A UserHandle represents a single user on Discord that the SDK knows about and contains basic account information for them such as id, name, and avatar, as well as their "status" information which includes both whether they are online/offline/etc as well as whether they are playing this game.

Handle objects in the SDK hold a reference both to the underlying data, and to the SDK instance. Changes to the underlying data will generally be available on existing handles objects without having to re-create them. If the SDK instance is destroyed, but you still have a reference to a handle object, note that it will return the default value for all method calls (ie an empty string for methods that return a string).

Public Member Functions

 UserHandle (UserHandle &&other) noexcept
 Move constructor for UserHandle.
 
UserHandleoperator= (UserHandle &&other) noexcept
 Move assignment operator for UserHandle.
 
 operator bool () const
 Returns true if the instance contains a valid object.
 
 UserHandle (const UserHandle &arg0)
 Copy constructor for UserHandle.
 
UserHandleoperator= (const UserHandle &arg0)
 Copy assignment operator for UserHandle.
 
std::optional< std::string > Avatar () const
 Returns the hash of the user's Discord profile avatar, if one is set.
 
std::string AvatarUrl (discordpp::UserHandle::AvatarType animatedType, discordpp::UserHandle::AvatarType staticType) const
 Returns a CDN url to the user's Discord profile avatar.
 
std::string DisplayName () const
 Returns the user's preferred name, if one is set, otherwise returns their unique username.
 
std::optional< discordpp::ActivityGameActivity () const
 Returns the user's rich presence activity that is associated with the current game, if one is set.
 
std::optional< std::string > GlobalName () const
 Returns the preferred display name of this user, if one is set.
 
uint64_t Id () const
 Returns the ID of this user.
 
bool IsProvisional () const
 Returns true if this user is a provisional account.
 
discordpp::RelationshipHandle Relationship () const
 Returns a reference to the RelationshipHandle between the currently authenticated user and this user, if any.
 
discordpp::StatusType Status () const
 Returns the user's online/offline/idle status.
 
std::string Username () const
 Returns the globally unique username of this user.
 

Public Types

enum class  AvatarType { Gif = 0 , Webp = 1 , Png = 2 , Jpeg = 3 }
 The desired type of avatar url to generate for a User. More...
 

Static Public Member Functions

static std::string AvatarTypeToString (discordpp::UserHandle::AvatarType type)
 Converts the AvatarType enum to a string.
 

Static Public Attributes

static const UserHandle nullobj
 Uninitialized instance of UserHandle.
 

Member Enumeration Documentation

◆ AvatarType

The desired type of avatar url to generate for a User.

Enumerator
Gif 

Gif.

Webp 

Webp.

Png 

Png.

Jpeg 

Jpeg.

Constructor & Destructor Documentation

◆ UserHandle() [1/2]

discordpp::UserHandle::UserHandle ( UserHandle && other)
noexcept

Move constructor for UserHandle.

◆ UserHandle() [2/2]

discordpp::UserHandle::UserHandle ( const UserHandle & arg0)

Copy constructor for UserHandle.

Member Function Documentation

◆ Avatar()

std::optional< std::string > discordpp::UserHandle::Avatar ( ) const

Returns the hash of the user's Discord profile avatar, if one is set.

◆ AvatarTypeToString()

static std::string discordpp::UserHandle::AvatarTypeToString ( discordpp::UserHandle::AvatarType type)
static

Converts the AvatarType enum to a string.

◆ AvatarUrl()

std::string discordpp::UserHandle::AvatarUrl ( discordpp::UserHandle::AvatarType animatedType,
discordpp::UserHandle::AvatarType staticType ) const

Returns a CDN url to the user's Discord profile avatar.

If the user does not have an avatar set, a url to one of Discord's default avatars is returned instead.

◆ DisplayName()

std::string discordpp::UserHandle::DisplayName ( ) const

Returns the user's preferred name, if one is set, otherwise returns their unique username.

◆ GameActivity()

std::optional< discordpp::Activity > discordpp::UserHandle::GameActivity ( ) const

Returns the user's rich presence activity that is associated with the current game, if one is set.

On Discord, users can have multiple rich presence activities at once, but the SDK will only expose the activity that is associated with your game. You can use this to know about the party the user is in, if any, and what the user is doing in the game.

For more information see the Activity class and check out https://discord.com/developers/docs/rich-presence/overview

◆ GlobalName()

std::optional< std::string > discordpp::UserHandle::GlobalName ( ) const

Returns the preferred display name of this user, if one is set.

Discord's public API refers to this as a "global name" instead of "display name".

Discord users can set their preferred name to almost any string.

For more information about usernames on Discord, see: https://discord.com/developers/docs/resources/user

◆ Id()

uint64_t discordpp::UserHandle::Id ( ) const

Returns the ID of this user.

If this returns 0 then the UserHandle is no longer valid.

◆ IsProvisional()

bool discordpp::UserHandle::IsProvisional ( ) const

Returns true if this user is a provisional account.

◆ operator bool()

discordpp::UserHandle::operator bool ( ) const
inline

Returns true if the instance contains a valid object.

◆ operator=() [1/2]

UserHandle & discordpp::UserHandle::operator= ( const UserHandle & arg0)

Copy assignment operator for UserHandle.

◆ operator=() [2/2]

UserHandle & discordpp::UserHandle::operator= ( UserHandle && other)
noexcept

Move assignment operator for UserHandle.

◆ Relationship()

discordpp::RelationshipHandle discordpp::UserHandle::Relationship ( ) const

Returns a reference to the RelationshipHandle between the currently authenticated user and this user, if any.

◆ Status()

discordpp::StatusType discordpp::UserHandle::Status ( ) const

Returns the user's online/offline/idle status.

◆ Username()

std::string discordpp::UserHandle::Username ( ) const

Returns the globally unique username of this user.

For provisional accounts this is an auto-generated string.

For more information about usernames on Discord, see: https://discord.com/developers/docs/resources/user

Member Data Documentation

◆ nullobj

const UserHandle discordpp::UserHandle::nullobj
static

Uninitialized instance of UserHandle.