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
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.
Enable the Public Client toggle in the OAuth2 tab.
This guide requires enabling Public Client to allow you to get started with the SDK quickly. Most games will not want to ship as a public client. This setting should be reviewed by your team prior to releasing your game. Learn more about public clients.
When shipping with the Social SDK, ensure you bundle the runtime dependencies:
Windows: Ensure discord_partner_sdk.dll is in your executable directory.
Linux/macOS: Make sure the libdiscord_partner_sdk.so/libdiscord_partner_sdk.dylib files are accessible via LD_LIBRARY_PATH or placed next to your binary.
To utilize the Discord Social SDK with C++, the following requirements must be met:
discordpp.h is 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
All of which can be found in the SDK download archive.
💡 Troubleshooting Tip: If you encounter unresolved external symbols, ensure the SDK library is correctly linked in your build system.
Let’s see this in action by starting with a folder for our project and the Social SDK dependency:
mkdir MyGamecd MyGamemkdir lib
Unzip the Social SDK archive into the 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:
touch CMakeLists.txt
Add the following contents to the CMakeLists.txt file to set up the Social SDK dependency appropriately for your operating system:
cmake_minimum_required(VERSION 3.10)project(DiscordSDKExample)set(CMAKE_CXX_STANDARD 17)set(CMAKE_CXX_STANDARD_REQUIRED True)add_executable(DiscordSDKExample main.cpp)# Define some handy Social SDK variablesset(DISCORD_SDK_ROOT "${CMAKE_SOURCE_DIR}/lib/discord_social_sdk")set(DISCORD_SDK_LIB_DIR "${DISCORD_SDK_ROOT}/lib/release")set(DISCORD_SDK_BIN_DIR "${DISCORD_SDK_ROOT}/bin/release")set(DISCORD_SDK_INCLUDE_DIR "${DISCORD_SDK_ROOT}/include")# Include for Social SDK headerstarget_include_directories(DiscordSDKExample PRIVATE ${DISCORD_SDK_INCLUDE_DIR})# Platform-specific Social SDK library pathsif(WIN32) set(DISCORD_LIB_PATH "${DISCORD_SDK_LIB_DIR}/discord_partner_sdk.lib") set(DISCORD_SHARED_LIB "${DISCORD_SDK_BIN_DIR}/discord_partner_sdk.dll")elseif(APPLE) set(DISCORD_LIB_PATH "${DISCORD_SDK_LIB_DIR}/libdiscord_partner_sdk.dylib") set(DISCORD_SHARED_LIB "${DISCORD_SDK_LIB_DIR}/libdiscord_partner_sdk.dylib")else() # Linux set(DISCORD_LIB_PATH "${DISCORD_SDK_LIB_DIR}/libdiscord_partner_sdk.so") set(DISCORD_SHARED_LIB "${DISCORD_SDK_LIB_DIR}/libdiscord_partner_sdk.so")endif()# Link the Social SDK librarytarget_link_libraries(DiscordSDKExample PRIVATE ${DISCORD_LIB_PATH})# Set the runtime search path (RPATH) for Linux and macOSif(UNIX) # Use RPATH when building set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) # Set the RPATH to use the lib directory relative to the executable set(CMAKE_INSTALL_RPATH "$ORIGIN") if(APPLE) set(CMAKE_INSTALL_RPATH "@executable_path") endif()endif()# Copy Social SDK shared library to output directory, so it's available at runtime.add_custom_command(TARGET DiscordSDKExample POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${DISCORD_SHARED_LIB}" $<TARGET_FILE_DIR:DiscordSDKExample>)
Create a main.cpp file:
touch main.cpp
Let’s add the following code to main.cpp:
#define DISCORDPP_IMPLEMENTATION#include "discordpp.h"#include <iostream>#include <thread>#include <atomic>#include <string>#include <functional>#include <csignal>// Replace with your Discord Application IDconst uint64_t APPLICATION_ID = 123456789012345678;// Create a flag to stop the applicationstd::atomic<bool> running = true;// Signal handler to stop the applicationvoid signalHandler(int signum) { running.store(false);}int main() { std::signal(SIGINT, signalHandler); std::cout << "🚀 Initializing Discord SDK...\n"; // Create our Discord Client auto client = std::make_shared<discordpp::Client>(); // Keep application running to allow SDK to receive events and callbacks while (running) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } return 0;}
Compile and run the project:
mkdir build && cd buildcmake ..cmake --build ../DiscordSDKExample
Although we’ve not done much yet other than create an instance of the client, you should see the following output printed to the console:
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.
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!
To get to a [Client::Status::Ready] state, we need to authenticate with Discord. We’ll do that shortly.
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 add RunCallbacks to our main loop:
// Keep application running to allow SDK to receive events and callbacks while (running) { discordpp::RunCallbacks(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); }
Add this code to your main.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.
// Generate OAuth2 code verifier for authenticationauto codeVerifier = client->CreateAuthorizationCodeVerifier();// Set up authentication argumentsdiscordpp::AuthorizationArgs args{};args.SetClientId(APPLICATION_ID);args.SetScopes(discordpp::Client::GetDefaultPresenceScopes());args.SetCodeChallenge(codeVerifier.Challenge());// Begin authentication processclient->Authorize(args, [client, codeVerifier](auto result, auto code, auto redirectUri) { if (!result.Successful()) { std::cerr << "❌ Authentication Error: " << result.Error() << std::endl; return; } else { std::cout << "✅ Authorization successful! Getting access token...\n"; // Exchange auth code for access token client->GetToken(APPLICATION_ID, code, codeVerifier.Verifier(), redirectUri, [client](discordpp::ClientResult result, std::string accessToken, std::string refreshToken, discordpp::AuthorizationTokenType tokenType, int32_t expiresIn, std::string scope) { std::cout << "🔓 Access token received! Establishing connection...\n"; // Next Step: Update the token and connect }); }});
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.Within client->SetStatusChangedCallback(), add the following after status == discordpp::Client::Status::Ready
code to view how many friends you have in Discord:
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.
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.
Need help? Join the Discord Developers Server and share questions in the #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