- Downloading the SDK
1.1. With the editor
1.2. Manually - Configure the SDK
- Modules
3.1. Discord SDK
3.2. Discord Core
3.3. Discord Achievement
3.4. Discord Activity
3.5. Discord Application
3.6. Discord Voice
3.7. Discord Image
3.8. Discord Lobby
3.9. Discord Networking
3.10. Discord Overlay
3.11. Discord Relationship
3.12. Discord Storage
3.13. Discord Store
3.14. Discord User
3.15. Discord Gateway
3.16. Discord HTTP API - Getting started
- Examples
5.1. Blueprint Examples
5.2. C++ Examples - Discord HTTP API
6.1. Webhooks - Discord Gateway
- Contact
Before using the plugin, you have to download the Discord Game SDK. To do so you have two options:
Start to open the configuration window by clicking on the Discord icon and choosing Configure the Discord SDK
:
In the configuration window, click on Download the SDK
:
Wait until the process is over, and it's already done, the Discord SDK is installed and ready to be used.
ℹ️ | If the installation fails, you'll have to download the SDK manually. Don't worry, it's not that difficult ! |
---|
First, start by downloading the last release of the Discord Game SDK from Discord's servers: discord_game_sdk.zip.
You then need to extract it to /DiscordFeatures/ThirdParty/DiscordSdk/
.
If it is installed correctly, the Discord Configuration Window
won't ask you to download the SDK.
Open the configuration window by clicking on the Discord icon and choosing Configure the Discord SDK
:
In the window, set your application ID with the one of your application. You can create and get your application ID from Discord. You can set your secret bot token as well if you plan to use the Discord editor tools.
The secret bot token is stored in an Editor-only config file called DiscordSdkEditor.ini . Think to exclude it from source control if needed. |
---|
The Discord Features Plugin is separated in several modules. Each module contains a set of functionalities.
To use one in C++, you have to add the module to your Build.cs
file:
PrivateDependencyModuleNames.Add("DiscordCore"); // Add one module
or to add more than one:
PrivateDependencyModuleNames.AddRange(new string[]
{
"DiscordLobby", // Add one...
"DiscordNetwork", // two...
"DiscordImage" // three modules
});
ℹ️ | You don't need to do anything for Blueprints and can just start using these modules. |
---|
This module handles the Discord SDK and load it correctly. It is done for you internally so you won't have to use it.
This is the core of the SDK. This is from where you have access to the managers.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/discord
C++ Module Name: DiscordCore
This is where are handled the achievements.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/achievements
C++ Module Name: DiscordAchievement
This is where are handled the users' activity and the so famous Rich Presence
.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/activities
C++ Module Name: DiscordActivity
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/applications
C++ Module Name: DiscordApplication
This is where to look if you want to implement voice chat in your game.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/discord-voice
C++ Module Name: DiscordVoice
This is where images are handle, including users avatars.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/images
C++ Module Name: DiscordImage
This is where multiplayer and lobbies are handled.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/lobbies
C++ Module Name: DiscordLobby
If you want to use Discord's Networking.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/networking
C++ Module Name: DiscordNetworking
To manage the build-in Discord overlay.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/overlay
C++ Module Name: DiscordOverlay
To manage the relationship between your players.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/relationships
C++ Module Name: DiscordRelationship
To store data on Discord's servers.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/storage
C++ Module Name: DiscordStorage
For in-app purchases and DLC.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/store
C++ Module Name: DiscordStore
To retrieve and manage user data.
Official Discord Documentation: https://discord.com/developers/docs/game-sdk/users
C++ Module Name: DiscordUser
Used to interact with the Discord Gateway.
Official Discord Documentation: https://discord.com/developers/docs/topics/gateway
C++ Module Name: DiscordGateway
ℹ️ | This module doesn't require the Discord Game SDK and is compatible with any platform. |
---|
Used to interact with the Discord API.
Official Discord Documentation: https://discord.com/developers/docs/resources/webhook
C++ Module Name: DiscordHttpApi
ℹ️ | This module doesn't require the Discord Game SDK and is compatible with any platform. |
---|
If you read the Discord Game SDK documentation or you already worked with the Discord Game SDK, you might know that the RunCallbacks
should be called every tick. However, you don't have to worry anymore for it ! Discord Features automatically call the RunCallbacks
function of Discord Core as well as the Flush
function of Discord Network Manager.
Discord Features tries to look as much as possible like the official Discord Game SDK documentation. You can refer to it to integrate Discord into your game and to the Blueprint Examples.
Nodes that require a callback as parameter have been implemented as a single asynchronous node with multiple output pins. It allows a faster development and to have a better view of your code:
ℹ️ | The On Error pin is executed if Result is not equal to EDiscordResult::Ok . |
---|
Here is an exhaustive list of includes available:
#include "DiscordCore.h" // For UDiscordCore
#include "DiscordAchievementManager.h" // For UDiscordAchievementManager
#include "DiscordActivityManager.h" // For UDiscordActivityManager
#include "DiscordApplicationManager.h" // For UDiscordApplicationManager
#include "DiscordImageManager.h" // For UDiscordImageManager
#include "DiscordLobbyManager.h" // For UDiscordLobbyManager
#include "DiscordNetworkManager.h" // For DiscordNetworkManager
#include "DiscordOverlayManager.h" // For UDiscordOverlayManager
#include "DiscordRelationshipManager.h" // For UDiscordRelationshipManager
#include "DiscordStorageManager.h" // For UDiscordStorageManager
#include "DiscordStoreManager.h" // For UDiscordStoreManager
#include "DiscordUserManager.h" // For UDiscordUserManager
#include "DiscordVoiceManager.h" // For UDiscordVoiceManager
#include "DiscordGatewaySocket.h" // For UDiscordGatewaySocket
#include "DiscordWebhookLibrary.h" // For FDiscordWebhookLibrary
The Discord Game SDK has several managers to handle functionalities. You can get those managers from a Discord Core
.
To get a manager in C++, you have to do the following:
UDiscordNetworkManager* Manager = UDiscordNetworkManager::GetNetworkManager(DiscordCore);
if (Manager)
{
// Do stuff with the manager
if (Manager->OpenChannel(456, 123, true) == EDiscordResult::Ok)
{
// ...
}
}
Aside from the specificity of getting a manager, Discord Features is used the exact same way as the official SDK. Each method has the same signature with the types of the Unreal Engine instead: Delegates
for Callbacks
, FString
for string
, etc.
This is why you can safely refer to the official Discord Game SDK documentation and to the C++ examples.
Creating the core is the starting point when you plan to integrate Discord in you game.
Make sure the Discord Core doesn't get garbage collected! The Core keeps a hard reference to the managers. The managers are valid while the Core is not garbage collected. |
---|
ℹ️ | If you run this code in editor without Discord in background, the Editor will close and launch Discord. |
---|
Rich Presence is really easy to implement:
UDiscordCore* DiscordCore = UDiscordCore::CreateDiscordCore(EDiscordCoreCreationFlags::Default);
if (DiscordCore)
{
// We have a valid Discord Core !
// We should keep it as a UPROPERTY() to prevent it
// from being garbage collected...
}
UDiscordActivityManager* ActivityManager = UDiscordActivityManager::GetActivityManager(DiscordCore);
if (ActivityManager)
{
FDiscordActivity Activity;
Activity.State = TEXT("In a dungeon...");
Activity.Details = TEXT("Slaying monsters !");
ActivityManager->UpdateActivity(Activity, FDiscordResultCallback::CreateLambda([](EDiscordResult Result)
{
if (Result == EDiscordResult::Ok)
{
// Activity has been updated !
}
else
{
// An error occured !
}
}));
}
UDiscordLobbyManager* LobbyManager = UDiscordLobbyManager::GetLobbyManager(DiscordCore);
UDiscordUserManager* UserManager = UDiscordUserManager::GetUserManager(DiscordCore);
if (LobbyManager && UserManager)
{
const FDiscordUser User = UserManager->GetCurrentUser();
FDiscordLobbyTransaction Transaction = LobbyManager->GetLobbyCreateTransaction();
Transaction.SetCapacity(10);
Transaction.SetLocked(false);
Transaction.SetMetadata(TEXT("SomeKey"), TEXT("SomeValue"));
Transaction.SetOwner(User.Id);
Transaction.SetType(EDiscordLobbyType::Private);
LobbyManager->CreateLobby(Transaction, FLobbyCallback::CreateLambda([](EDiscordResult Result, FDiscordLobby& Lobby)
{
if (Result == EDiscordResult::Ok)
{
// Lobby created.
}
else
{
// An error occured !
}
}));
}
You can send a message to a channel with Webhooks. These messages can contain embed content as well.
#include "DiscordWebhookLibrary.h"
// ...
// Get information about the Webhook we want to execute.
FDiscordWebhookLibrary::GetWebhook
(
9823290121, // Webhook Snowflake.
// Callback called when the information about the Webhook has been received.
FDiscordGetWebhook::CreateLambda([](const FDiscordWebhook& Webhook) -> void
{
FDiscordWebhookData MessageToSend;
MessageToSend.Username = TEXT("My UE4 Bot"); // Username displayed with the message
MessageToSend.Avatar = TEXT("..."); // Avatar displayed with the message
MessageToSend.Content = TEXT("Hello @everyone."); // Message content.
// MessageToSend.Embeds for embeds, MessageToSend.File for files, ...
// Finally execute the Webhook.
FDiscordWebhookLibrary::ExecuteWebhook
(
Webhook.Id,
Webhook.Token,
MessageToSend,
FDiscordExecuteWebhook::CreateLambda([](const bool bExecuted) -> void
{
if (bExecuted)
{
// Message posted.
}
else
{
// An error occured, see the output log!
}
})
);
})
);
Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use. Discord - Features offers a library to easily interact with the Discord HTTP API without needing to touch HTTP requests.
Name | Description |
---|---|
CreateWebhook |
Create a new WebHook. |
GetChannelWebhooks |
Returns a list of channel webhook objects. Requires the MANAGE_WEBHOOKS permission. |
GetGuildWebhooks |
Returns a list of channel webhook objects. Requires the MANAGE_WEBHOOKS permission. |
GetWebhook |
Returns the webhook object for the given id. |
GetWebhookWithToken |
Returns the webhook object for the given id. |
ModifyWebhook |
Modify a webhook. Requires the MANAGE_WEBHOOKS permission. Returns the updated webhook object on success. |
ModifyWebhookWithToken |
Modify a webhook. Requires the MANAGE_WEBHOOKS permission. Returns the updated webhook object on success. |
DeleteWebhook |
Delete a webhook permanently. |
DeleteWebhookWithToken |
Delete a webhook permanently. |
ExecuteWebhook |
Execute the Webhook. |
To use the Webhooks, you need to have enough credentials to do so. An easy way to do it is to create a bot and get a secret bot token. Copy the secret Bot Token to the Discord HTTP API settings window located in Project Settings > Plugins > Discord HTTP API
.
This method should be used for Dedicated Servers. Be careful that your token doesn't get distributed with your game to the players. The token is stored in DiscordHttpApi.ini , see Unreal Engine Config System to make per-build config files. |
---|
The Discord Gateway can be used to establish a real-time communication with the Discord API over secure WebSockets. This plugin offers an interface to interact with the Discord Gateway.
You can connect to the Gateway with the Connect To Discord Gateway
node:
Once you have a UDiscordGatewaySocket
object, you can start sending and receiving commands to/from the Discord Gateway.
If you need help, spotted a bug, have a feature request or experience troubles, please contact us at [email protected].