Discord Integration Sample¶
This demo, showcases how you can use the Unreal SDK and Beamable Microservices to integrate with Discord for community management tools.
Introduction¶
Aside from our BeamableCore
Plugin, here's what the sample contains:
BEAMPROJ_DiscordDemo
Unreal Plugin.: Contains the UE implementation for the client.Microservices/services/DiscordDemo
Microservice: Microservice containing code that implements IFederatedLogin and aDiscordBot
integration.
To set up this sample you'll need a few things:
- A Beamable Account and a Realm.
- A Discord Developer Account.
To configure the sample, run dotnet beam unreal select-sample BEAMPROJ_DiscordDemo
.
Assumptions
Instructions below assume that you already have the Discord server that you want to use for integration. If that is not the case create one first. Make sure that you have the admin access to the Discord server of choice.
Setting Discord Application¶
Since this sample requires several resources, we do not host it ourselves. So, in order to access the sample we'll go set up a Discord account and setup the sample Discord bot:
- Log into your Discord.dev account.
- Create an App. Set aside its
AppId
in a notepad for future use.- Fill out General Information about your app.
- No need for providing any of the URLs at the bottom of the General Information page.
- Go to App
Settings->OAuth2
and set the Redirects Url:http://127.0.0.1
. Make sure that changes are saved. - Go to App
Settings->Bot
.- Set a Bot username.
- Set as true all Privileged Gateway Intents, especially the Server Members Intent.
- Press the
Reset Token
button and set it aside (it will be required later on).
- Go to App
Settings->Installation
.- In
Install Link
selectDiscord Provided Link
, copy and paste it into browser. - In
Default Install Settings
addbot
to theScopes
field andAdministrator
to thePermissions
field - Install the App into your Discord server of choice.
- In
- Now open the Discord application.
- Open
Settings->Advanced
and enable theDeveloper Mode
so that we can copy various Ids by right-clicking things in the UI. - Right click on the server icon and select the option
Copy server ID
and set it aside. - Right click on the server icon and select
Settings->Roles
. - Create a
enabled-matchmaking
role. - Right click on the role and select the option
Copy Role ID
and set it aside. - Pick any text channel. Right click on the channel select the option
Copy Channel ID
and set it aside.
- Open
Setting up Beamable¶
Now, you'll need to configure a Beamable realm so you can use it.
- Go to the Beamable Portal and create a new Beamable realm called
discord-demo
. - On the Portal open the Realm Config page of the
discord-demo
realm (Operate -> Config
). - Hit the
Add Config
button. - Set the following key-value pairs for the namespace
discord_integration
:matchmaking_roles_whitelist -> Your copied Role Id, can be multiple separated by comma
bot_token -> Your Bot Token
guild_id -> Your Discord Server ID
notify_channel -> Optional- Discord channel ID that bot will notify about status changes
- Open the
Plugins/BEAMPROJ_DiscordDemo/Overrides/Config/DefaultGame.ini
.- Replace the
DiscordAppId
in it withYour App Id
. - Regenerate project files.
- Replace the
- Compile and open the
BeamableUnreal
editor (it'll be configured as theBEAMPROJ_DiscordDemo
) project.
Now, you are ready to sign into a game using Discord.
Playing the sample in Editor¶
In order to test the sample:
- Open the
BeamableUnreal
in the Unreal Editor - Sign into your Beamable account in the
Beamable Window
and go to thediscord-demo
realm. - Go to the
Microservices
and run theDiscordSampleMS
microservice. - Start game.
- Press the
Sign In with Discord
button following instructions (discord will ask for permission). - After logging in, you should see information about being able to participate in matchmaking.
- Adding and/or removing the role to the signed in user on Discord Server.
- Observe the text on the UI changing to reflect your ability to participate in matchmaking.
- Also, if
notify_channel
was specified correctly in configuration bot should inform about status change:
In order to actually gate matchmaking you'll need to set up a rule in your GameType
content that excludes people from the queue that do not have the role. This is not shown on this demo.
Can I use it as a Template?¶
This sample is not meant to be used as a template directly, however, its components are free for you to copy and use in your own project. Here's what these are:
- The
DiscordDemo
Microservice. - Beamable code inside
BEAMPROJ_DiscordDemo
except code inside aThirdParty
directory. - Content inside the
BEAMPROJ_DiscordDemo
except things inside aThirdParty
directory.
Why don't we provide a client build?¶
Because clients must be pointed at your discord-demo
realm. As such, you'd need to generate the build yourself, which you can do by packaging it normally for any of our supported platforms.