D++ (DPP)
C++ Discord API Bot Library
dpp::guild_member Class Reference

Represents dpp::user membership upon a dpp::guild. This contains the user's nickname, guild roles, and any other guild-specific flags. More...

+ Inheritance diagram for dpp::guild_member:
+ Collaboration diagram for dpp::guild_member:

Public Member Functions

 guild_member ()
 
guild_memberfill_from_json (nlohmann::json *j, snowflake g_id, snowflake u_id)
 Fill this object from a json object. More...
 
bool is_communication_disabled () const
 Returns true if the user is in time-out (communication disabled) More...
 
bool is_deaf () const
 Returns true if the user is deafened. More...
 
bool is_muted () const
 Returns true if the user is muted. More...
 
bool is_pending () const
 Returns true if pending verification by membership screening. More...
 
bool has_rejoined () const
 Returns true if the user has left and rejoined the guild. More...
 
bool has_completed_onboarding () const
 Returns true if the user has completed onboarding. More...
 
bool has_started_onboarding () const
 Returns true if the user has started onboarding. More...
 
bool has_bypasses_verification () const
 Returns true if the user is exempt from guild verification requirements. More...
 
bool has_animated_guild_avatar () const
 Returns true if the user's per-guild custom avatar is animated. More...
 
std::string get_avatar_url (uint16_t size=0, const image_type format=i_png, bool prefer_animated=true) const
 Returns the member's per guild avatar url if they have one, otherwise returns an empty string. More...
 
guild_memberset_nickname (const std::string &nick)
 Set the nickname. More...
 
std::string get_nickname () const
 Get the nickname. More...
 
const std::vector< dpp::snowflake > & get_roles () const
 Get the roles. More...
 
userget_user () const
 Find the dpp::user object for this member. This is an alias for dpp::find_user. More...
 
bool operator== (guild_member const &other_member) const
 Check if this member is equal to another member object. More...
 
guild_memberset_bypasses_verification (const bool is_bypassing_verification)
 Set whether the user is exempt from guild verification requirements. More...
 
guild_memberset_mute (const bool is_muted)
 Set whether the user is muted in voice channels. More...
 
guild_memberset_deaf (const bool is_deafened)
 Set whether the user is deafened in voice channels. More...
 
guild_memberset_communication_disabled_until (const time_t timestamp)
 Set communication_disabled_until. More...
 
std::string get_mention () const
 Return a ping/mention for the user by nickname. More...
 
guild_memberadd_role (dpp::snowflake role_id)
 Add a role to this member. More...
 
guild_memberremove_role (dpp::snowflake role_id)
 Remove a role from this member. More...
 
guild_memberset_roles (const std::vector< dpp::snowflake > &role_ids)
 Set a new role list for this member. More...
 
template<typename U = T, typename = decltype(std::declval<U&>().fill_from_json_impl(std::declval<nlohmann::json*>()))>
T & fill_from_json (nlohmann::json *j)
 Convert object from nlohmann::json. More...
 
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
auto to_json (bool with_id=false) const
 Convert object to nlohmann::json. More...
 
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
std::string build_json (bool with_id=false) const
 Convert object to json string. More...
 

Public Attributes

snowflake guild_id
 Guild id. More...
 
snowflake user_id
 User id. More...
 
utility::iconhash avatar
 User avatar. More...
 
time_t communication_disabled_until
 Timestamp of when the time out will be removed; until then, they cannot interact with the guild. More...
 
time_t joined_at
 Date and time the user joined the guild. More...
 
time_t premium_since
 The Date and time the user started boosting. More...
 

Protected Member Functions

json to_json_impl (bool with_id=false) const
 Build json for the member object. More...
 

Protected Attributes

std::string nickname
 Nickname. More...
 
std::vector< snowflakeroles
 List of roles this user has on this guild. More...
 
uint16_t flags
 A set of flags built from the bitmask defined by dpp::guild_member_flags. More...
 

Friends

struct json_interface< guild_member >
 
void from_json (const nlohmann::json &j, guild_member &gm)
 helper function to deserialize a guild_member from json More...
 

Detailed Description

Represents dpp::user membership upon a dpp::guild. This contains the user's nickname, guild roles, and any other guild-specific flags.

Constructor & Destructor Documentation

◆ guild_member()

dpp::guild_member::guild_member ( )

Default constructor

Member Function Documentation

◆ add_role()

guild_member& dpp::guild_member::add_role ( dpp::snowflake  role_id)

Add a role to this member.

Note
This call sets the role change bit, which causes the new role list to be sent if this is passed to dpp::cluster::guild_edit_member or dpp::cluster::guild_add_member
Parameters
role_idRole ID to add
Returns
guild_member& Reference to self

◆ build_json()

template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
std::string dpp::json_interface< T >::build_json ( bool  with_id = false) const
inlineinherited

Convert object to json string.

Parameters
with_idWhether 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() [1/2]

template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().fill_from_json_impl(std::declval<nlohmann::json*>()))>
T& dpp::json_interface< T >::fill_from_json ( nlohmann::json *  j)
inlineinherited

Convert object from nlohmann::json.

Parameters
jnlohmann::json object
Returns
T& Reference to self for fluent calling

◆ fill_from_json() [2/2]

guild_member& dpp::guild_member::fill_from_json ( nlohmann::json *  j,
snowflake  g_id,
snowflake  u_id 
)

Fill this object from a json object.

Parameters
jThe json object to get data from
g_idThe guild id to associate the member with
u_idThe user id to associate the member with
Returns
Reference to self for call chaining

◆ get_avatar_url()

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

Returns the member's per guild avatar url if they have one, otherwise returns an empty string.

Note
per-server avatar is a nitro only feature so it might be not set. If you need the user avatar, use user::get_avatar_url.
Parameters
sizeThe size of the avatar in pixels. It can be any power of two between 16 and 4096, otherwise the default sized avatar is returned.
formatThe 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_animatedWhether 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_mention()

std::string dpp::guild_member::get_mention ( ) const

Return a ping/mention for the user by nickname.

Returns
std::string mention

◆ get_nickname()

std::string dpp::guild_member::get_nickname ( ) const

Get the nickname.

Returns
std::string nickname

◆ get_roles()

const std::vector<dpp::snowflake>& dpp::guild_member::get_roles ( ) const

Get the roles.

Returns
std::vector<dpp::snowflake> roles

◆ get_user()

user* dpp::guild_member::get_user ( ) const

Find the dpp::user object for this member. This is an alias for dpp::find_user.

Returns
dpp::user* Pointer to the user object. If not in cache, it returns nullptr

◆ has_animated_guild_avatar()

bool dpp::guild_member::has_animated_guild_avatar ( ) const

Returns true if the user's per-guild custom avatar is animated.

Returns
true user's custom avatar is animated
false user's custom avatar is not animated

◆ has_bypasses_verification()

bool dpp::guild_member::has_bypasses_verification ( ) const

Returns true if the user is exempt from guild verification requirements.

Returns
true user bypasses verification
false user doesn't bypass verification

◆ has_completed_onboarding()

bool dpp::guild_member::has_completed_onboarding ( ) const

Returns true if the user has completed onboarding.

Returns
true user has completed onboarding
false user has not completed onboarding

◆ has_rejoined()

bool dpp::guild_member::has_rejoined ( ) const

Returns true if the user has left and rejoined the guild.

Returns
true user has left and rejoined the guild
false user has not rejoined

◆ has_started_onboarding()

bool dpp::guild_member::has_started_onboarding ( ) const

Returns true if the user has started onboarding.

Returns
true user has started onboarding
false user has not started onboarding yet

◆ is_communication_disabled()

bool dpp::guild_member::is_communication_disabled ( ) const

Returns true if the user is in time-out (communication disabled)

Returns
true user is in time-out
false user is not in time-out

◆ is_deaf()

bool dpp::guild_member::is_deaf ( ) const

Returns true if the user is deafened.

Returns
true user is deafened
false user is not deafened

◆ is_muted()

bool dpp::guild_member::is_muted ( ) const

Returns true if the user is muted.

Returns
true user muted
false user not muted

◆ is_pending()

bool dpp::guild_member::is_pending ( ) const

Returns true if pending verification by membership screening.

Returns
true user has completed membership screening
false user has not completed membership screening

◆ operator==()

bool dpp::guild_member::operator== ( guild_member const &  other_member) const

Check if this member is equal to another member object.

Parameters
other_memberother member object to compare
Returns
true if their user ids are equal, false otherwise.

◆ remove_role()

guild_member& dpp::guild_member::remove_role ( dpp::snowflake  role_id)

Remove a role from this member.

Note
This call sets the role change bit, which causes the new role list to be sent if this is passed to dpp::cluster::guild_edit_member or dpp::cluster::guild_add_member
Parameters
role_idRole ID to remove
Returns
guild_member& Reference to self

◆ set_bypasses_verification()

guild_member& dpp::guild_member::set_bypasses_verification ( const bool  is_bypassing_verification)

Set whether the user is exempt from guild verification requirements.

Parameters
is_bypassing_verificationvalue to set
Returns
guild_member& reference to self

◆ set_communication_disabled_until()

guild_member& dpp::guild_member::set_communication_disabled_until ( const time_t  timestamp)

Set communication_disabled_until.

Parameters
timestamptimestamp until communication is disabled
Returns
guild_member& reference to self

◆ set_deaf()

guild_member& dpp::guild_member::set_deaf ( const bool  is_deafened)

Set whether the user is deafened in voice channels.

Parameters
is_deafenedvalue to set, true if deaf in voice channels
Returns
guild_member& reference to self

◆ set_mute()

guild_member& dpp::guild_member::set_mute ( const bool  is_muted)

Set whether the user is muted in voice channels.

Parameters
is_mutedvalue to set, true if mute in voice channels
Returns
guild_member& reference to self

◆ set_nickname()

guild_member& dpp::guild_member::set_nickname ( const std::string &  nick)

Set the nickname.

Parameters
nickNickname to set
Returns
guild_member& reference to self

◆ set_roles()

guild_member& dpp::guild_member::set_roles ( const std::vector< dpp::snowflake > &  role_ids)

Set a new role list for this member.

Note
This call sets the role change bit, which causes the new role list to be sent if this is passed to dpp::cluster::guild_edit_member or dpp::cluster::guild_add_member
Parameters
role_idsRoles to set
Returns
guild_member& Reference to self

◆ to_json()

template<typename T >
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))>
auto dpp::json_interface< T >::to_json ( bool  with_id = false) const
inlineinherited

Convert object to nlohmann::json.

Parameters
with_idWhether 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()

json dpp::guild_member::to_json_impl ( bool  with_id = false) const
protected

Build json for the member object.

Parameters
with_idAdd ID to output
Returns
json JSON object

Friends And Related Function Documentation

◆ from_json

void from_json ( const nlohmann::json &  j,
guild_member gm 
)
friend

helper function to deserialize a guild_member from json

See also
https://github.com/nlohmann/json#arbitrary-types-conversions
Parameters
joutput json object
gmguild_member to be deserialized

◆ json_interface< guild_member >

friend struct json_interface< guild_member >
friend

Member Data Documentation

◆ avatar

utility::iconhash dpp::guild_member::avatar

User avatar.

Note
Per-server avatar is a nitro only feature.

◆ communication_disabled_until

time_t dpp::guild_member::communication_disabled_until

Timestamp of when the time out will be removed; until then, they cannot interact with the guild.

◆ flags

uint16_t dpp::guild_member::flags
protected

A set of flags built from the bitmask defined by dpp::guild_member_flags.

◆ guild_id

snowflake dpp::guild_member::guild_id

Guild id.

◆ joined_at

time_t dpp::guild_member::joined_at

Date and time the user joined the guild.

◆ nickname

std::string dpp::guild_member::nickname
protected

Nickname.

Note
Empty string if they don't have a nickname on this guild

◆ premium_since

time_t dpp::guild_member::premium_since

The Date and time the user started boosting.

◆ roles

std::vector<snowflake> dpp::guild_member::roles
protected

List of roles this user has on this guild.

◆ user_id

snowflake dpp::guild_member::user_id

User id.

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