Discord Social SDK
|
Discord models the relationship between two users using the Relationship entity in the SDK. Relationships are not just for friends though, they are also for sending and receiving friend requests, as well as blocking other users.
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.
We know that sometimes users will want to be friends with each other across all their games, that way if they start playing a new game they can see all of their previous friends and don't start from scratch. But sometimes they don't want to give out that access and only want to be friends in the current game they are playing.
So, the SDK supports two types of relationships between users:
discordpp::RelationshipHandle can be used to determine the type of friendship that exists. It has two fields:
One reason having both of these friend types is important is because a pair of users might start out as being game friends, but later choose to "upgrade" to being full Discord friends. In this case, their discordpp::RelationshipHandle::DiscordRelationshipType would be set to discordpp::RelationshipType::PendingIncoming or discordpp::RelationshipType::PendingOutgoing (based on whether they are receiving or sending the request respectively), and their discordpp::RelationshipHandle::GameRelationshipType would remain as discordpp::RelationshipType::Friend.
While our API technically supports users being both types of friends, you don't have to ensure that every Discord friend is also a game friend or vice versa. When adding friends, offer users a choice of friend type and explain the difference. See our design guidelines for more.
Since there are two types of relationships, each relationship action in the SDK has two variants, one for each friend type. For example to send a friend request, you must call either discordpp::Client::SendDiscordFriendRequest or discordpp::Client::SendGameFriendRequest based on which type of friend the user wants to be.
discordpp::RelationshipType::Blocked is a special relationship type. When a user blocks another user, it is always stored on the discordpp::RelationshipHandle::DiscordRelationshipType field, and will persist across games. It is not possible to block a user in only one game. Blocking a user will also remove any existing relationship (game or Discord) between the users and cancel any pending requests.
Users are limited to 1,000 Discord friends. There is currently no limit on game friends but one will be added in the future.
Here's a small code snippet that demonstrates all the APIs you may need to use in order to construct a friends list using the Discord SDK. To do that you'll need to query all relationships, and then find out the name and type of each user, what type of friend they are, whether they are online. The example below should print out all of a users friends to your console for debugging: