Discord Social SDK
|
An Activity represents one "thing" a user is doing on Discord and is part of their rich presence.
Additional information is located on the Discord Developer Portal:
While RichPresence supports multiple types of activities, the only activity type that is really relevant for the SDK is ActivityTypes::Playing. Additionally, the SDK will only expose Activities that are associated with the current game (or application). So for example, a field like name
below, will always be set to the current game's name from the view of the SDK.
When an activity shows up on Discord, it will look something like this:
You can control how lines 2 and 3 are rendered in Discord, here's the breakdown:
Playing "game name"
is powered by the name of your game (or application) on Discord.Capture the flag | 2 - 1
is powered by the details
field in the activity, and this should generally try to describe what the player is currently doing. You can even include dynamic data such as a match score here.In a group (2 of 3)
describes the party the player is in. "Party" is used to refer to a group of players in a shared context, such as a lobby, server, team, etc. The first half, In a group
is powered by the state
field in the activity, and the second half, (2 of 3)
is powered by the party
field in the activity and describes how many people are in the current party and how big the party can get.This diagram visually shows the field mapping:
You can also specify up to two custom buttons to display on the rich presence. These buttons will open the URL in the user's default browser.
Other users can be invited to join the current player's activity (or request to join it too), but that does require certain fields to be set:
There is additional information about game invites here: https://support.discord.com/hc/en-us/articles/115001557452-Game-Invites
Activity invites are handled via a deep link. To enable users to join your game via an invite in the Discord client, you must do two things:
When the user accepts the invite, the Discord client will open: [your url]/_discord/join?secret=[the join secret you set]
If you are using Discord lobbies for your game, a neat flow would look like this:
Users can also request to join each others parties. This code snippet shows how that flow might look:
Public Member Functions | |
Activity (Activity &&other) noexcept | |
Move constructor for Activity. | |
Activity & | operator= (Activity &&other) noexcept |
Move assignment operator for Activity. | |
operator bool () const | |
Returns true if the instance contains a valid object. | |
Activity (const Activity &arg0) | |
Copy constructor for Activity. | |
Activity & | operator= (const Activity &arg0) |
Copy assignment operator for Activity. | |
void | AddButton (discordpp::ActivityButton button) |
Adds a custom button to the rich presence. | |
bool | Equals (discordpp::Activity other) const |
Compares each field of the Activity struct for equality. | |
std::vector< discordpp::ActivityButton > | GetButtons () const |
Returns the custom buttons for the rich presence. | |
std::string | Name () const |
The name of the game or application that the activity is associated with. | |
void | SetName (std::string Name) |
Setter for Activity::Name. | |
discordpp::ActivityTypes | Type () const |
The type of activity this is. | |
void | SetType (discordpp::ActivityTypes Type) |
Setter for Activity::Type. | |
std::optional< std::string > | State () const |
The state of the party for this activity. | |
void | SetState (std::optional< std::string > State) |
Setter for Activity::State. | |
std::optional< std::string > | Details () const |
The state of the what the user is doing for this activity. | |
void | SetDetails (std::optional< std::string > Details) |
Setter for Activity::Details. | |
std::optional< uint64_t > | ApplicationId () const |
The application ID of the game that the activity is associated with. | |
void | SetApplicationId (std::optional< uint64_t > ApplicationId) |
Setter for Activity::ApplicationId. | |
std::optional< discordpp::ActivityAssets > | Assets () const |
Images used to customize how the Activity is displayed in the Discord client. | |
void | SetAssets (std::optional< discordpp::ActivityAssets > Assets) |
Setter for Activity::Assets. | |
std::optional< discordpp::ActivityTimestamps > | Timestamps () const |
The timestamps struct can be used to render either: | |
void | SetTimestamps (std::optional< discordpp::ActivityTimestamps > Timestamps) |
Setter for Activity::Timestamps. | |
std::optional< discordpp::ActivityParty > | Party () const |
The party struct is used to indicate the size and members of the people the current user is playing with. | |
void | SetParty (std::optional< discordpp::ActivityParty > Party) |
Setter for Activity::Party. | |
std::optional< discordpp::ActivitySecrets > | Secrets () const |
The secrets struct is used in combination with the party struct to make an Activity joinable. | |
void | SetSecrets (std::optional< discordpp::ActivitySecrets > Secrets) |
Setter for Activity::Secrets. | |
discordpp::ActivityGamePlatforms | SupportedPlatforms () const |
If an activity is joinable, but only on certain platforms, this field can be used to indicate which platforms the activity is joinable on. For example if a game is available on both PC and Mobile, but PC users cannot join Mobile users and vice versa, this field can be used so that an activity only shows as joinable on Discord if the user is on the appropriate platform. | |
void | SetSupportedPlatforms (discordpp::ActivityGamePlatforms SupportedPlatforms) |
Setter for Activity::SupportedPlatforms. | |
Static Public Attributes | |
static const Activity | nullobj |
Uninitialized instance of Activity. | |
void discordpp::Activity::AddButton | ( | discordpp::ActivityButton | button | ) |
Adds a custom button to the rich presence.
std::optional< uint64_t > discordpp::Activity::ApplicationId | ( | ) | const |
The application ID of the game that the activity is associated with.
This field cannot be set by the SDK, and will always be the application ID of the current game.
std::optional< discordpp::ActivityAssets > discordpp::Activity::Assets | ( | ) | const |
Images used to customize how the Activity is displayed in the Discord client.
std::optional< std::string > discordpp::Activity::Details | ( | ) | const |
The state of the what the user is doing for this activity.
See the docs on the Activity struct for more info. If specified, must be a string between 2 and 128 characters.
bool discordpp::Activity::Equals | ( | discordpp::Activity | other | ) | const |
Compares each field of the Activity struct for equality.
std::vector< discordpp::ActivityButton > discordpp::Activity::GetButtons | ( | ) | const |
Returns the custom buttons for the rich presence.
std::string discordpp::Activity::Name | ( | ) | const |
The name of the game or application that the activity is associated with.
This field cannot be set by the SDK, and will always be the name of the current game.
|
inline |
Returns true if the instance contains a valid object.
Move assignment operator for Activity.
Copy assignment operator for Activity.
std::optional< discordpp::ActivityParty > discordpp::Activity::Party | ( | ) | const |
The party struct is used to indicate the size and members of the people the current user is playing with.
std::optional< discordpp::ActivitySecrets > discordpp::Activity::Secrets | ( | ) | const |
The secrets struct is used in combination with the party struct to make an Activity joinable.
void discordpp::Activity::SetApplicationId | ( | std::optional< uint64_t > | ApplicationId | ) |
Setter for Activity::ApplicationId.
void discordpp::Activity::SetAssets | ( | std::optional< discordpp::ActivityAssets > | Assets | ) |
Setter for Activity::Assets.
void discordpp::Activity::SetDetails | ( | std::optional< std::string > | Details | ) |
Setter for Activity::Details.
void discordpp::Activity::SetName | ( | std::string | Name | ) |
Setter for Activity::Name.
void discordpp::Activity::SetParty | ( | std::optional< discordpp::ActivityParty > | Party | ) |
Setter for Activity::Party.
void discordpp::Activity::SetSecrets | ( | std::optional< discordpp::ActivitySecrets > | Secrets | ) |
Setter for Activity::Secrets.
void discordpp::Activity::SetState | ( | std::optional< std::string > | State | ) |
Setter for Activity::State.
void discordpp::Activity::SetSupportedPlatforms | ( | discordpp::ActivityGamePlatforms | SupportedPlatforms | ) |
Setter for Activity::SupportedPlatforms.
void discordpp::Activity::SetTimestamps | ( | std::optional< discordpp::ActivityTimestamps > | Timestamps | ) |
Setter for Activity::Timestamps.
void discordpp::Activity::SetType | ( | discordpp::ActivityTypes | Type | ) |
Setter for Activity::Type.
std::optional< std::string > discordpp::Activity::State | ( | ) | const |
The state of the party for this activity.
See the docs on the Activity struct for more info. If specified, must be a string between 2 and 128 characters.
discordpp::ActivityGamePlatforms discordpp::Activity::SupportedPlatforms | ( | ) | const |
If an activity is joinable, but only on certain platforms, this field can be used to indicate which platforms the activity is joinable on. For example if a game is available on both PC and Mobile, but PC users cannot join Mobile users and vice versa, this field can be used so that an activity only shows as joinable on Discord if the user is on the appropriate platform.
std::optional< discordpp::ActivityTimestamps > discordpp::Activity::Timestamps | ( | ) | const |
The timestamps struct can be used to render either:
end
value)start
value) discordpp::ActivityTypes discordpp::Activity::Type | ( | ) | const |
The type of activity this is.
This should almost always be set to Playing