Overview
This guide will walk you through integrating the Discord Social SDK into a new standalone C++ project. By the end, you’ll have an application that can:- Authenticate users with Discord
- Set up logging and status monitoring
- Start the SDK and establish a connection
- Request the number of Discord friends the player has
- Set the player’s rich presence for your game
Prerequisites
We are going to make a simple C++ console application for this guide. Make sure you have the following prerequisites:- Basic understanding of C++ and your platform’s build system
- C++ Compiler and Build System that supports C++17 or greater.
- A network connection that can access Discord’s API endpoints.
Step 1: Create a Discord Developer Team
Before you start, you’ll need to create a developer team on the Discord Developer Portal. This team will be used to manage your Discord applications and SDK integrations. If you already have a team configured, you can skip this step.- Create a developer team on the Discord Developer Portal.
Step 2: Create a Discord Application
- Create a new application on the Discord Developer Portal and assign it to your team.
- Add a redirect URL in the OAuth2 tab:
- For desktop applications:
http://127.0.0.1/callback(this can be changed later). - See
discordpp::Client::Authorizefor more details on setting up more advanced redirect URIs.
- For desktop applications:
- Enable the
Public Clienttoggle in the OAuth2 tab.
Step 3: Enable Discord Social SDK for Your App
Once you’ve created your Discord application, you’ll need to enable the Discord Social SDK for it.- From the Discord Developer Portal, select your newly created application from Step 2.
- In the left sidebar for your app, locate and click the Getting Started link under
Discord Social SDK. - Fill out the form to share details about your game.
- Click
Submitand the Social SDK will be enabled for your application. - Once enabled, you’ll find binaries for the Social SDK under Downloads.
Step 4: Download the Discord SDK for C++
- Click on the Downloads link under the Discord Social SDK section of the sidebar.
- Select the latest version from the version dropdown and download the SDK for C++.
Runtime Dependencies
When shipping with the Social SDK, ensure you bundle the runtime dependencies:- Windows: Ensure
discord_partner_sdk.dllis in your executable directory. - Linux/macOS: Make sure the
libdiscord_partner_sdk.so/libdiscord_partner_sdk.dylibfiles are accessible viaLD_LIBRARY_PATHor placed next to your binary.
Step 5: Project Setup
To utilize the Discord Social SDK with C++, the following requirements must be met:discordpp.his included in your C++ source code.- The appropriate SDK libraries for your platform are linked in your build system:
- Windows:
discord_partner_sdk.dll - Linux:
discord_partner_sdk.so - macOS:
discord_partner_sdk.dylib
- Windows:
💡 Troubleshooting Tip: If you encounter unresolved external symbols, ensure the SDK library is correctly linked in your build system.
lib directory. You should end up with a discord_social_sdk folder under lib when complete.
Within the MyGame directory, create a CMakeLists.txt file:
CMakeLists.txt file to set up the Social SDK dependency appropriately for your operating system:
main.cpp:
Troubleshooting
Mac libdiscord_partner_sdk.dylib Not Opened
Mac libdiscord_partner_sdk.dylib Not Opened
On Mac you may get the error “libdiscord_partner_sdk.dylib” Not Opened because Apple couldn’t verify it. If this happens press Done on the popup.
You’ll need to open your System Settings > Privacy & Security and scroll down to the Security section. It will tell you “libdiscord_partner_sdk.dylib” was blocked to protect your Mac. Press Open Anyway and try running again.
Now when you get the pop up you’ll have the option to select Open Anyway and it will be able to use it successfully.



Step 6: Setting Up SDK Event Handling
Let’s add some event handlers to monitor what’s happening with our Discord connection. We’ll set up two important callbacks:- A logging callback to see what the SDK is doing
- A status callback to know when we can start using Discord features
Adding Logging Support
First, let’s add logging so we can see what’s happening:Monitoring Connection Status
Next, let’s add a status callback that tells us when we’re ready to use Discord features:main.cpp with event handling
main.cpp with event handling
Most Discord features won’t work until the status is [
Client::Status::Ready]. The status callback lets you know exactly when you can start using them.What These Callbacks Do
- The logging callback shows you what’s happening behind the scenes
- The status callback tells you when you’re connected and ready to use Discord features
At this point, these callbacks won’t get called since the client setup is not yet complete. However, very soon we will be using them to view debug information and see what our connection status is!
Client::Status::Ready] state, we need to authenticate with Discord. We’ll do that shortly.
Step 7: Run Callbacks
Once you’ve registered callbacks with the SDK, you’ll need to execute them in the event loop of your program. Add something like this to your game’s main event loop or tick function. Let’s addRunCallbacks to our main loop:
Step 8: Account Linking with Discord
In this step, we’ll implement OAuth2 authentication to support account-linking with Discord. This process will:- Open the Discord app or a browser window for Discord login
- Get an authorization code
- Exchange it for an access token
- Connect to Discord
Add the Authentication Code
Add this code to yourmain.cpp after setting up the status callback:
Choosing your OAuth2 scopes: This guide uses
Client::GetDefaultPresenceScopes, which requests the openid and sdk.social_layer_presence scopes. These enable core features like account linking, friends list, and rich presence.If your game also needs lobbies, voice chat, or direct messaging, use Client::GetDefaultCommunicationScopes instead.
See the OAuth2 Scopes guide for the full breakdown.What’s Happening Here?
- We create a code verifier for OAuth2 PKCE security
- Set up authorization arguments with your app ID and required scopes
- Start the auth flow with
Client::Authorize, which opens a browser - When authorized, we exchange the code for an access token
Testing It Out
- Build and run your program
- A browser window should open asking you to authorize your app
- After authorizing, watch the console for the ”🔓 Access token received!” message
- Double check your APPLICATION_ID is correct
- Ensure you’ve added the redirect URL in your Discord Developer Portal
- Check the console for specific error messages
main.cpp with Account Linking
main.cpp with Account Linking
Step 9: Connect the SDK to Discord
Now that we have our access token, let’s connect to Discord! This involves two steps:- Updating the SDK with our access token with
Client::UpdateToken. - Establishing the connection with
Client::Connect.
// Next Step: Update the token and connect within client->UpdateToken(), and add the
following code after:
What’s Happening Here?
client->UpdateToken()tells the SDK to use our access token for Discord API calls- Once the token is updated, we call
client->Connect()in the callback - The SDK will begin connecting asynchronously
- Our status callback (from Step 6) will tell us when we’re ready
Watch your console output! You should see status updates as the connection is established.
Testing the Connection
- Run your program
- Watch for these status messages in order:
- ”🔑 Token updated, connecting to Discord…”
- ”🔄 Status changed: Connecting” (also “Connected” and “Ready”)
- ”✅ Client is ready! You can now call SDK functions.”
Troubleshooting
If you don’t see “Ready” status:- Check that your access token is valid
- Ensure you have internet connectivity
- Look for error messages in the status callback
- Verify your
APPLICATION_IDis correct
main.cpp with SDK connection
main.cpp with SDK connection
Step 10: Access Discord Relationships
Let’s access the user’s Discord relationships (friends list) and display the count. This will help you understand how to access and use Discord data in your game. Withinclient->SetStatusChangedCallback(), add the following after status == discordpp::Client::Status::Ready
code to view how many friends you have in Discord:
What This Code Does
Client::GetRelationshipsgives you immediate access to the current friend list
Example Output
Testing It Out
- Run your program
- Wait for the initial friend count
This relationship data forms the foundation for features like friend lists, activity feeds, and multiplayer invites!
Troubleshooting
If you’re not seeing relationship data:- Verify your OAuth2 scopes include relationships access
- Ensure you’re connected (Status::Ready)
- Check that you have friends on Discord
- Look for errors in the logging callback
main.cpp with friends count
main.cpp with friends count
Step 11: Set Rich Presence
Let’s show your game’s activity on Discord using Rich Presence. This feature lets players see what others are doing in your game directly in their Discord friends list.Add Rich Presence Code
Right after the line where we calledclient->GetRelationships() let’s add the following code to set the your rich
presence:
What This Code Does
- Creates an
Activityobject to represent what the player is doing - Sets basic information like:
- The activity type (Playing)
- Current state (“In Competitive Match”)
- Additional details (“Rank: Diamond II”)
- Updates your rich presence on Discord
Testing It Out
- Run your program
- Watch for the console message ”🎮 Rich Presence updated successfully!”
- Check your Discord profile, you should see:
- “Playing [Your Game]”
- “In Competitive Match”
- “Rank: Diamond II”
Troubleshooting
If you don’t see your presence:- Ensure you’re connected ([
Client::Status::Ready]) - Check the callback for error messages
- Verify your activity settings are valid
- Make sure you’re not invisible on Discord
main.cpp complete
main.cpp complete
Conclusion
Congratulations! You’ve successfully integrated the Discord Social SDK into your C++ application. Let’s review what you’ve accomplished:What You’ve Built
- ✅ Created a Discord application and configured OAuth2
- ✅ Set up SDK logging and status monitoring
- ✅ Implemented user authentication flow
- ✅ Retrieved Discord relationships data
- ✅ Added Rich Presence support
Key Concepts Learned
- How to initialize and configure the Discord SDK
- Managing authentication and connections
- Working with Discord’s social features
- Handling asynchronous callbacks
- Monitoring SDK status and events
Next Steps
You have successfully set up the Discord Social SDK with C++ and authenticated with Discord! You can now use the SDK to add more social features in your project.Creating a Unified Friends List
Create a unified friends list combining Discord and game-specific friendships
Setting Rich Presence
Customize your game’s rich presence to show more advanced information and game invites
Managing Game Invites
Allow players to invite friends to join their game session or party.
#social-sdk-dev-help channel for support from the community.
If you encounter a bug while working with the Social SDK, please report it here: https://dis.gd/social-sdk-bug-report