Overview
This guide will walk you through integrating the Discord Social SDK into a Unity 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
- Set the player’s rich presence for your game
Prerequisites
Before starting, ensure you have:- Unity 2021.3 or later
- A Discord application created in the Developer Portal
Step 1: Create your Discord application
- Go to the Discord Developer Portal and click New Application.
- Give your application a name and click Create.
- Copy your Application ID — you’ll need it in the Unity inspector.
Step 2: Configure OAuth2 redirect URIs
- In your application settings, click OAuth2 in the sidebar.
- Under Redirects, add
http://127.0.0.1/callback. - Click Save Changes.
Step 3: Enable public client (optional)
If your application does not have a backend server, enable Public Client in the OAuth2 settings.Step 4: Download the Social SDK for Unity
- In your application settings, click Downloads under the Discord Social SDK section in the sidebar.
- Select the latest version from the dropdown and download the SDK for Unity.
A Unity sample project is also available on the downloads page. Explore it after completing this guide.
Step 5: Project setup
- Create a new 2D project in Unity Hub using Unity 2021.3 or later.
- Either unzip the SDK archive into the Unity
Packagesfolder, or unzip it and install the package from disk. - In your project, add a
Scriptsfolder and create aDiscordManager.csscript. - Add the following initial code to
DiscordManager.cs:
- Add an empty GameObject to the scene (GameObject > Create Empty) called DiscordManager and attach the script.
- Add a button (GameObject > UI > Legacy > Button) and text (GameObject > UI > Legacy > Text) to the scene.
- Attach the button and text to the DiscordManager in the inspector.
- Enter your Application ID in the Client Id field in the inspector.
Step 6: Set up SDK event handling
Add callbacks to monitor your Discord connection. UpdateDiscordManager.cs:
The Unity plugin handles running SDK callbacks automatically — no need to call
RunCallbacks() manually like in the C++ guide.Step 7: Account linking with Discord
Implement OAuth2 authentication to connect users with their Discord accounts.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 details.DiscordManager.cs:
Start():
Step 8: Connect the SDK to Discord
Add the token handling methods and updateGetTokenFromCode to call them:
GetTokenFromCode:
Ready.
Step 9: Access Discord relationships
Add a method to display friend count when the client is ready:OnStatusChanged to call it:
Step 10: Set rich presence
UpdateClientReady to also set rich presence:
Conclusion
You’ve successfully integrated the Discord Social SDK into Unity.What you’ve built
- A Discord application configured with OAuth2
- SDK logging and status monitoring
- User authentication flow
- Discord relationships data retrieval
- Rich Presence support
Next steps
Check out the Unity sample project on GitHub for drop-in prefabs with both code and UI to quickly integrate Discord’s social features into your game.Creating a unified friends list
Build a unified friends list combining Discord and game-specific friendships.
Setting rich presence
Customize your game’s rich presence to show advanced information and game invites.
Managing lobbies
Bring players together in a shared lobby with text chat and voice communication.
Change log
| Date | Changes |
|---|---|
| March 17, 2025 | Initial release |