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

Detailed Description

A RelationshipHandle represents the relationship between the current user and a target user on Discord. Relationships include friends, blocked users, and friend invites.

The SDK supports two types of relationships:

  • Discord: These are relationships that persist across games and on the Discord client. Both users will be able to see whether each other is online regardless of whether they are in the same game or not.
  • Game: These are per-game relationships and do not carry over to other games. The two users will only be able to see if the other is online if they are playing a game in which they are friends.

If someone is a game friend they can later choose to "upgrade" to a full Discord friend. In this case, the user has two relationships at the same time, which is why there are two different type fields on RelationshipHandle. In this example, their RelationshipHandle::DiscordRelationshipType would be set to RelationshipType::PendingIncoming or RelationshipType::PendingOutgoing (based on whether they are receiving or sending the invite respectively), and their RelationshipHandle::GameRelationshipType would remain as RelationshipType::Friend.

When a user blocks another user, it is always stored on the RelationshipHandle::DiscordRelationshipType field, and will persist across games. It is not possible to block a user in only one game.

See the Friends documentation for more information.

Note: While the SDK allows you to manage a user's relationships, you should never take an action without their explicit consent. You should not automatically send or accept friend requests. Only invoke APIs to manage relationships in response to a user action such as clicking a "Send Friend Request" button.

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

 RelationshipHandle (RelationshipHandle &&other) noexcept
 Move constructor for RelationshipHandle.
 
RelationshipHandleoperator= (RelationshipHandle &&other) noexcept
 Move assignment operator for RelationshipHandle.
 
 operator bool () const
 Returns true if the instance contains a valid object.
 
 RelationshipHandle (const RelationshipHandle &other)
 Copy constructor for RelationshipHandle.
 
RelationshipHandleoperator= (const RelationshipHandle &other)
 Copy assignment operator for RelationshipHandle.
 
discordpp::RelationshipType DiscordRelationshipType () const
 Returns the type of the Discord relationship.
 
discordpp::RelationshipType GameRelationshipType () const
 Returns the type of the Game relationship.
 
uint64_t Id () const
 Returns the ID of the target user in this relationship.
 
std::optional< discordpp::UserHandleUser () const
 Returns a handle to the target user in this relationship, if one is available. This would be the user with the same ID as the one returned by the Id() method.
 

Static Public Attributes

static const RelationshipHandle nullobj
 Uninitialized instance of RelationshipHandle.
 

Constructor & Destructor Documentation

◆ RelationshipHandle() [1/2]

discordpp::RelationshipHandle::RelationshipHandle ( RelationshipHandle && other)
noexcept

Move constructor for RelationshipHandle.

◆ RelationshipHandle() [2/2]

discordpp::RelationshipHandle::RelationshipHandle ( const RelationshipHandle & other)

Copy constructor for RelationshipHandle.

Member Function Documentation

◆ DiscordRelationshipType()

discordpp::RelationshipType discordpp::RelationshipHandle::DiscordRelationshipType ( ) const

Returns the type of the Discord relationship.

◆ GameRelationshipType()

discordpp::RelationshipType discordpp::RelationshipHandle::GameRelationshipType ( ) const

Returns the type of the Game relationship.

◆ Id()

uint64_t discordpp::RelationshipHandle::Id ( ) const

Returns the ID of the target user in this relationship.

◆ operator bool()

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

Returns true if the instance contains a valid object.

◆ operator=() [1/2]

RelationshipHandle & discordpp::RelationshipHandle::operator= ( const RelationshipHandle & other)

Copy assignment operator for RelationshipHandle.

◆ operator=() [2/2]

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

Move assignment operator for RelationshipHandle.

◆ User()

std::optional< discordpp::UserHandle > discordpp::RelationshipHandle::User ( ) const

Returns a handle to the target user in this relationship, if one is available. This would be the user with the same ID as the one returned by the Id() method.

Member Data Documentation

◆ nullobj

const RelationshipHandle discordpp::RelationshipHandle::nullobj
static

Uninitialized instance of RelationshipHandle.