| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::user Class Reference

Represents a user on discord. May or may not be a member of a dpp::guild. More...

`#include <user.h>`

Inheritance diagram for dpp::user:
[legend]
Collaboration diagram for dpp::user:
[legend]

## Public Member Functions

| user ()
| Construct a new user object.
virtual | ~user ()=default
| Destroy the user object.
std::string | build_json (bool with_id=false) const
| Convert object to json string.
user & | fill_from_json (nlohmann::json *j)
| Convert object from nlohmann::json.
std::string | format_username () const
| Format a username into user#discriminator.
std::string | get_avatar_decoration_url (uint16_t size=0) const
| Get the avatar decoration url of the user if they have one, otherwise returns an empty string.
std::string | get_avatar_url (uint16_t size=0, const image_type format=i_png, bool prefer_animated=true) const
| Get the avatar url of the user.
constexpr double | get_creation_time () const noexcept
| Get the creation time of this object according to Discord.
std::string | get_default_avatar_url () const
| Get the default avatar url of the user. This is calculated by the discriminator.
std::string | get_mention () const
| Return a ping/mention for the user.
std::string | get_url () const
| Returns URL to user.
bool | has_animated_icon () const
| Return true if user has an animated icon.
bool | has_hypesquad_events () const
| Return true if user has hypesquad events.
bool | has_nitro_basic () const
| Return true if user has nitro basic. This is mutually exclusive with nitro basic.
bool | has_nitro_classic () const
| Return true if user has nitro classic. This is mutually exclusive with nitro classic.
bool | has_nitro_full () const
| Return true if user has full nitro. This is mutually exclusive with full nitro.
bool | is_active_developer () const
| Return true if user has the active Developer badge.
bool | is_bot () const
| User is a bot.
bool | is_bot_http_interactions () const
| Return true if user is a bot which exclusively uses HTTP interactions. Bots using HTTP interactions are always considered online even when not connected to a websocket.
bool | is_bughunter_1 () const
| Return true if user has the bughunter level 1 badge.
bool | is_bughunter_2 () const
| Return true if user has the bughunter level 2 badge.
bool | is_certified_moderator () const
| Return true if user is a certified moderator.
bool | is_discord_employee () const
| Return true if user is a discord employee.
bool | is_early_supporter () const
| Return true if user is an early supporter.
bool | is_house_balance () const
| Return true if user is in house balance.
bool | is_house_bravery () const
| Return true if user is in house bravery.
bool | is_house_brilliance () const
| Return true if user is in house brilliance.
bool | is_mfa_enabled () const
| User has multi-factor authentication enabled.
bool | is_partnered_owner () const
| Return true if user owns a partnered server.
bool | is_system () const
| User is a system user (Clyde).
bool | is_team_user () const
| Return true if user is a team user.
bool | is_verified () const
| Return true if user has verified account.
bool | is_verified_bot () const
| Return true if user has the verified bot badge.
bool | is_verified_bot_dev () const
| Return true if user is an early verified bot developer.
constexpr bool | operator!= (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
constexpr bool | operator== (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
auto | to_json (bool with_id=false) const
| Convert object to nlohmann::json.

## Static Public Member Functions

static std::string | get_mention (const snowflake &id)
| Create a mentionable user.

## Public Attributes

utility::iconhash | avatar
| Avatar hash.
utility::iconhash | avatar_decoration
| Avatar decoration hash.
uint16_t | discriminator
| Discriminator (aka tag), 4 digits usually displayed with leading zeroes.
uint32_t | flags
| Flags built from a bitmask of values in dpp::user_flags.
std::string | global_name
| Global display name.
snowflake | id = {}
| Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.
utility::primaryguild | primary_guild
| Primary guild object (server tag).
uint8_t | refcount
| Reference count of how many guilds this user is in.
std::string | username
| Discord username.

## Protected Member Functions

user & | fill_from_json_impl (nlohmann::json *j)
virtual json | to_json_impl (bool with_id=true) const
| Convert to JSON.

## Friends

struct | json_interface< user >

## Detailed Description

Represents a user on discord. May or may not be a member of a dpp::guild.

## Constructor & Destructor Documentation

## ◆ user()

dpp::user::user | ( |  | ) |

Construct a new user object.

## ◆ ~user()

virtual dpp::user::~user | ( |  | ) |

virtual default

Destroy the user object.

## Member Function Documentation

## ◆ build_json()

std::string dpp::json_interface< user >::build_json | ( | bool | with_id = false | ) | const

inline inherited

Convert object to json string.

Parameters

  with_id | Whether to include the ID or not

Note
  Some fields are conditionally filled, do not rely on all fields being present

Returns
  std::string Json built from the structure

## ◆ fill_from_json()

user & dpp::json_interface< user >::fill_from_json | ( | nlohmann::json * | j | ) |

inline inherited

Convert object from nlohmann::json.

Parameters

  j | nlohmann::json object

Returns
  T& Reference to self for fluent calling

## ◆ fill_from_json_impl()

user & dpp::user::fill_from_json_impl | ( | nlohmann::json * | j | ) |

protected

Fill this record from json.

Parameters

  j | The json to fill this record from

Returns
  Reference to self

## ◆ format_username()

std::string dpp::user::format_username | ( |  | ) | const

Format a username into user#discriminator.

For example Brain#0001

Note
  This will, most often, return something like Brain#0000 due to discriminators slowly being removed. Some accounts, along with most bots, still have discriminators, so they will still show as Bot#1234.

Returns
  Formatted username and discriminator

## ◆ get_avatar_decoration_url()

std::string dpp::user::get_avatar_decoration_url | ( | uint16_t | size = 0 | ) | const

Get the avatar decoration url of the user if they have one, otherwise returns an empty string.

Parameters

  size | The size of the avatar decoration in pixels. It can be any power of two between 16 and 4096, otherwise the default sized avatar decoration is returned.

Returns
  std::string avatar url or an empty string

## ◆ get_avatar_url()

std::string dpp::user::get_avatar_url | ( | uint16_t | size = 0,
|  | const image_type | format = i_png,
|  | bool | prefer_animated = true ) const

Get the avatar url of the user.

Note
  If the user doesn't have an avatar, the default user avatar url is returned which is always in png format!

Parameters

  size | The size of the avatar in pixels. It can be any power of two between 16 and 4096, otherwise the default sized avatar is returned.
  format | The format to use for the avatar. It can be one of i_webp, i_jpg, i_png or i_gif. When passing i_gif, it returns an empty string for non-animated images. Consider using the prefer_animated parameter instead.
  prefer_animated | Whether you prefer gif format. If true, it'll return gif format whenever the image is available as animated.

Returns
  std::string avatar url or an empty string, if required attributes are missing or an invalid format was passed

## ◆ get_creation_time()

double dpp::managed::get_creation_time | ( |  | ) | const

inline constexpr noexcept inherited

Get the creation time of this object according to Discord.

Returns
  double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.

## ◆ get_default_avatar_url()

std::string dpp::user::get_default_avatar_url | ( |  | ) | const

Get the default avatar url of the user. This is calculated by the discriminator.

Returns
  std::string avatar url or an empty string, if the discriminator is empty

## ◆ get_mention() [1/2]

std::string dpp::user::get_mention | ( |  | ) | const

Return a ping/mention for the user.

Returns
  std::string mention

## ◆ get_mention() [2/2]

std::string dpp::user::get_mention | ( | const snowflake & | id | ) |

static

Create a mentionable user.

Parameters

  id | The ID of the user.

Returns
  std::string The formatted mention of the user.

## ◆ get_url()

std::string dpp::user::get_url | ( |  | ) | const

Returns URL to user.

Returns
  string of URL to user

## ◆ has_animated_icon()

bool dpp::user::has_animated_icon | ( |  | ) | const

Return true if user has an animated icon.

Returns
  true if icon is animated (gif)

## ◆ has_hypesquad_events()

bool dpp::user::has_hypesquad_events | ( |  | ) | const

Return true if user has hypesquad events.

Returns
  true if has hypesquad events

## ◆ has_nitro_basic()

bool dpp::user::has_nitro_basic | ( |  | ) | const

Return true if user has nitro basic. This is mutually exclusive with nitro basic.

Returns
  true if user has nitro basic

## ◆ has_nitro_classic()

bool dpp::user::has_nitro_classic | ( |  | ) | const

Return true if user has nitro classic. This is mutually exclusive with nitro classic.

Returns
  true if user has nitro classic

## ◆ has_nitro_full()

bool dpp::user::has_nitro_full | ( |  | ) | const

Return true if user has full nitro. This is mutually exclusive with full nitro.

Returns
  true if user has full nitro

## ◆ is_active_developer()

bool dpp::user::is_active_developer | ( |  | ) | const

Return true if user has the active Developer badge.

Returns
  true if has active developer

## ◆ is_bot()

bool dpp::user::is_bot | ( |  | ) | const

User is a bot.

Returns
  True if the user is a bot

## ◆ is_bot_http_interactions()

bool dpp::user::is_bot_http_interactions | ( |  | ) | const

Return true if user is a bot which exclusively uses HTTP interactions. Bots using HTTP interactions are always considered online even when not connected to a websocket.

Returns
  true if is a http interactions only bot

## ◆ is_bughunter_1()

bool dpp::user::is_bughunter_1 | ( |  | ) | const

Return true if user has the bughunter level 1 badge.

Returns
  true if has bughunter level 1

## ◆ is_bughunter_2()

bool dpp::user::is_bughunter_2 | ( |  | ) | const

Return true if user has the bughunter level 2 badge.

Returns
  true if has bughunter level 2

## ◆ is_certified_moderator()

bool dpp::user::is_certified_moderator | ( |  | ) | const

Return true if user is a certified moderator.

Returns
  true if certified moderator

## ◆ is_discord_employee()

bool dpp::user::is_discord_employee | ( |  | ) | const

Return true if user is a discord employee.

Returns
  true if user is discord staff

## ◆ is_early_supporter()

bool dpp::user::is_early_supporter | ( |  | ) | const

Return true if user is an early supporter.

Returns
  true if early supporter

## ◆ is_house_balance()

bool dpp::user::is_house_balance | ( |  | ) | const

Return true if user is in house balance.

Returns
  true if in house brilliance

## ◆ is_house_bravery()

bool dpp::user::is_house_bravery | ( |  | ) | const

Return true if user is in house bravery.

Returns
  true if in house bravery

## ◆ is_house_brilliance()

bool dpp::user::is_house_brilliance | ( |  | ) | const

Return true if user is in house brilliance.

Returns
  true if in house brilliance

## ◆ is_mfa_enabled()

bool dpp::user::is_mfa_enabled | ( |  | ) | const

User has multi-factor authentication enabled.

Returns
  true if multi-factor is enabled

## ◆ is_partnered_owner()

bool dpp::user::is_partnered_owner | ( |  | ) | const

Return true if user owns a partnered server.

Returns
  true if user has partnered server

## ◆ is_system()

bool dpp::user::is_system | ( |  | ) | const

User is a system user (Clyde).

Returns
  true if user is a system user

## ◆ is_team_user()

bool dpp::user::is_team_user | ( |  | ) | const

Return true if user is a team user.

Returns
  true if a team user

## ◆ is_verified()

bool dpp::user::is_verified | ( |  | ) | const

Return true if user has verified account.

Returns
  true if verified

## ◆ is_verified_bot()

bool dpp::user::is_verified_bot | ( |  | ) | const

Return true if user has the verified bot badge.

Returns
  true if verified bot

## ◆ is_verified_bot_dev()

bool dpp::user::is_verified_bot_dev | ( |  | ) | const

Return true if user is an early verified bot developer.

Returns
  true if verified bot developer

## ◆ operator!=()

bool dpp::managed::operator!= | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other object to compare against

Returns
  true objects are not the same id
  false objects are the same id

## ◆ operator==()

bool dpp::managed::operator== | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other object to compare against

Returns
  true objects are the same id
  false objects are not the same id

## ◆ to_json()

auto dpp::json_interface< user >::to_json | ( | bool | with_id = false | ) | const

inline inherited

Convert object to nlohmann::json.

Parameters

  with_id | Whether to include the ID or not

Note
  Some fields are conditionally filled, do not rely on all fields being present

Returns
  json Json built from the structure

## ◆ to_json_impl()

virtual json dpp::user::to_json_impl | ( | bool | with_id = true | ) | const

protected virtual

Convert to JSON.

Parameters

  with_id | include ID in output

Returns
  json JSON output

Reimplemented in dpp::user_identified.

## Friends And Related Symbol Documentation

## ◆ json_interface< user >

friend struct json_interface< user >

friend

## Member Data Documentation

## ◆ avatar

utility::iconhash dpp::user::avatar

Avatar hash.

## ◆ avatar_decoration

utility::iconhash dpp::user::avatar_decoration

Avatar decoration hash.

## ◆ discriminator

uint16_t dpp::user::discriminator

Discriminator (aka tag), 4 digits usually displayed with leading zeroes.

Note
  To print the discriminator with leading zeroes, use format_username(). 0 for users that have migrated to the new username format.

## ◆ flags

uint32_t dpp::user::flags

Flags built from a bitmask of values in dpp::user_flags.

## ◆ global_name

std::string dpp::user::global_name

Global display name.

## ◆ id

snowflake dpp::managed::id = {}

inherited

Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.

## ◆ primary_guild

utility::primaryguild dpp::user::primary_guild

Primary guild object (server tag).

## ◆ refcount

uint8_t dpp::user::refcount

Reference count of how many guilds this user is in.

## ◆ username

std::string dpp::user::username

Discord username.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0