Skip to main content

Overview

This guide will walk you through integrating the Discord Social SDK into an Unreal Engine project. By the end, you’ll have a project 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
For the initial launch, the Unreal plugin has a name of DiscordPartnerSDK but this name will be changing to DiscordSocialSDK in a future version

Prerequisites

We are going to make a simple Unreal console application for this guide. Make sure you have the following prerequisites:
  • Windows
  • Visual Studio 2022
  • Unreal Engine 5.5
Let’s walk through the steps in detail.

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.
  1. Create a developer team on the Discord Developer Portal.
Later, you can invite your team members to your new team to collaborate on your integration.

Step 2: Create a Discord Application

  1. Create a new application on the Discord Developer Portal and assign it to your team.
  2. 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::Authorize for more details on setting up more advanced redirect URIs.
  3. 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.

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.
  1. From the Discord Developer Portal, select your newly created application from Step 2.
  2. In the left sidebar for your app, locate and click the Getting Started link under Discord Social SDK.
  3. Fill out the form to share details about your game.
  4. Click Submit and the Social SDK will be enabled for your application.
  5. Once enabled, you’ll find binaries for the Social SDK under Downloads.

Step 4: Download the Social SDK for Unreal Engine

  1. Click on the Downloads link under the Discord Social SDK section of the sidebar.
  2. Select the latest version from the version dropdown and download the SDK for Unreal Engine.
A Unreal Engine sample project is available for download on this page, but we are not going to cover it in this guide. Explore it on your own after you finish this guide!

Step 5: Project Setup

Create a new Unreal Engine project

Select Third Person Unreal project (C++ language). We’ll set the project name to DiscordSocialUnreal.
The code samples below assume the project name is DiscordSocialUnreal. If you use a different name, make sure to replace it in the code.
Wait for the shaders to compile. This can take a while.

Add the Discord SDK to the project

Locate your Unreal project in the Windows file explorer. Create a new directory named Plugins in the base of your project directory (DiscordSocialUnreal/Plugins). Extract the Discord SDK archive in the Plugins directory. You should end up with a directory called DiscordPartnerSDK inside of Plugins DiscordSocialUnreal/Plugins/DiscordPartnerSDK.
Double check the name of the DiscordPartnerSDK folder once you’ve extracted it. It may change between versions and you’ll need to add the correct name in the code below.
Reload Unreal Editor and open the project. It should ask if you’d like to recompile the DiscordPartnerSDK plugin on launch. Open Visual Studio from the Tools -> Open Visual Studio menu in Unreal Editor. Open your DiscordSocialUnreal.Build.cs file located at /Source/DiscordSocialUnreal/ and add the following line after PublicDependencyModuleNames array:
Back in Unreal Editor, refresh the Visual Studio Project from the Tools -> Refresh Visual Studio Project menu. In the Unreal Editor, compile the code with Ctrl-Alt-F11. You should see a “Live coding succeeded” modal window if the compilation is successful.

Step 6: Initialize the SDK

In this section, we’ll add callbacks for logging and status of the SDK and OAuth2 authentication to support account linking with Discord. This process will:
  1. Open the Discord app or a browser window for Discord login
  2. Get an authorization code
  3. Exchange it for an access token
  4. Connect to Discord
Building for mobile? On iOS and Android you only need to configure your Discord Application ID in Project Settings. Set that up in the Account Linking on Mobile guide, then continue here. The rest of this step is the same for mobile.
Choosing your OAuth2 scopes: This guide uses UDiscordClient::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 UDiscordClient::GetDefaultCommunicationScopes() instead. See the OAuth2 Scopes guide for the full breakdown.
Open DiscordSocialUnrealCharacter.h in Visual Studio, where we start integrating the Social SDK!

DiscordLocalPlayerSubsystem

To use the Social SDK with Unreal Engine, we will need to include the DiscordLocalPlayerSubsystem which is responsible for managing the lifecycle of the client and executing the RunCallbacks event loop. Add the following code to DiscordSocialUnrealCharacter.h:
Now let’s add the following functions to the public section of the DiscordSocialUnrealCharacter class:
DiscordSocialUnrealCharacter.h
And add the following functions to the protected section of the DiscordSocialUnrealCharacter class:
DiscordSocialUnrealCharacter.h
Now let’s add the implementation of these functions to the DiscordSocialUnrealCharacter.cpp file. In the DiscordSocialUnrealCharacter.cpp file, add the following code:
DiscordSocialUnrealCharacter.cpp

What’s Happening Here?

  1. We create a code verifier for OAuth2 PKCE security
  2. Set up authorization arguments with your app ID and required scopes
  3. Start the auth flow with Client::Authorize, which opens a browser
  4. When authorized, we exchange the code for an access token
  5. Client::UpdateToken tells the SDK to use our access token for Discord API calls
  6. Once the token is updated, we call Client::Connect, and the SDK will begin connecting asynchronously

Testing It Out

Save your changes in Visual Studio and return to Unreal Editor. Compile the code in Unreal Editor with Ctrl-Alt-F11 Enter play mode and find the console at the bottom of Unreal Editor. Run DiscordConnect as a command to start the account linking process.
If Discord is open on your computer, you should see a prompt to authorize the connection. Click “Authorize” to continue. If the connection is successful, you should see a message in the Unreal Editor console that says, “Connected to Discord! Ready to go! You can now start using Discord features.”
Most Discord features won’t work until the status is Ready. The status callback lets you know when you can start using them.

Troubleshooting

  • Double check your APPLICATION_ID is correct
  • Ensure you’ve added the redirect URL in your Discord Developer Portal
  • Check the output log for specific error messages
  • Check that your access token is valid
  • Ensure you have internet connectivity
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.ErrorYou’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.SettingsNow when you get the pop up you’ll have the option to select Open Anyway and it will be able to use it successfully.Open
Now that your client is in a ready state, we can start implementing Discord social features.

Step 7: 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. Add this code to the Ready section of OnStatusChanged:

What This Code Does

Now, when the client status is Ready, we’ll call Client::GetRelationships, returning us a list of all the player’s friends. We then log the number of friends directly to the output log.

Testing It Out

Save your changes in Visual Studio and return to Unreal Editor. Compile the code in Unreal Editor with Ctrl-Alt-F11 Enter play mode, and find the console at the bottom of Unreal Editor, run DiscordConnect.

Example Output

Troubleshooting

  • Verify your OAuth2 scopes include relationships access
  • Ensure you’re connected (status is Ready)
  • Check that you have friends on Discord
  • Look for errors in the output log
Next, we’ll learn how to show your game’s activity on Discord with Rich Presence!

Step 8: 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 this code to the Ready section of OnStatusChanged:
Then add this new method:

What This Code Does

  1. Creates an Activity object to represent what the player is doing
  2. Sets basic information like:
  • The activity type (Playing)
  • Current state (“In Competitive Match”)
  • Additional details (“Rank: Diamond II”)
  1. Updates your rich presence on Discord

Testing It Out

Save your changes in Visual Studio and return to Unreal Editor. Compile the code in Unreal Editor with Ctrl-Alt-F11 Enter play mode and find the console at the bottom of Unreal Editor. Run DiscordConnect. Once the OAuth flow is complete, the output log will tell you if setting rich presence was successful, and you can check your Discord profile to see it!

Troubleshooting

If you don’t see your presence:
  • Ensure you’re connected (status is Ready)
  • Check the output log for error messages
  • Verify your activity settings are valid
  • Make sure you’re not invisible on Discord


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 Unreal Engine 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

Change Log