Skip to main content

Discord Social SDK Features

System version requirements

If the system version falls between the two, the plugin can be integrated but its functions will be disabled.

Step 1: Configure Discord Application

info

If you have completed Discord login configuration, you may skip the application creation step.

1.1 Create an application

  1. Register and authenticate your account on the Discord official website.
  2. Go to the Developer Platform and click New Application.

Image: Create Application

  1. Enter your application name and click Create.
  2. On the General Information page, obtain the APPLICATION ID.

Image: Obtain App ID

  1. Configure the Discord App ID in INTLConfig.ini.

1.2 Apply for SDK access

  1. Go to the Developer Platform.
  2. Click Getting Started, fill out the form, and submit.

Image: Fill in form 1

Image: Fill in form 2

Important

Before the official launch of your game, notify the Discord team in advance to enable production permissions.

1.3 Configure OAuth2

  1. Click OAuth2 and turn on the PUBLIC CLIENT option.

Image: PUBLIC CLIENT

  1. Configure Redirects:
    • Android/iOS: discord-{YOUR_APP_ID}:/authorize/callback
    • PC: http://127.0.0.1/callback

Image: Configure Redirects

note

For mobile, configure DeepLink: add the jump URL in General InformationDeep Link URL.

Image: DeepLink configuration

1.4 Configure Rich Presence assets

  1. Click Rich Presence.
  2. Click Add Image(s) to upload image assets.

Image: Upload assets

Step 2: Register Callback

note

It is recommended to register all callbacks when the game starts.

General Function Callback

// Add/remove callbacks
INTLAPI.AddDiscordBaseResultObserver(OnDiscordBaseResult);
INTLAPI.RemoveDiscordBaseResultObserver(OnDiscordBaseResult);

// Handle callback
private void OnDiscordBaseResult(INTLBaseResult baseRet)
{
switch (baseRet.MethodId)
{
case (int)INTLMethodID.INTL_FRIEND_DISCORD_AUTHORIZE:
// Authorization callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_CREATE_LOBBY:
// Create/join lobby callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_LEAVE_LOBBY:
// Leave lobby callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_SET_RICH_PRESENCE:
// Set game status callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_SEND_MESSAGE:
// Send message callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_REMOVE_FRIEND:
// Remove friend callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_ADD_FRIEND_BY_ID:
// Add friend by ID callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_ADD_FRIEND_BY_NAME:
// Add friend by username callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_ACCEPT_FRIEND_REQUEST:
// Accept friend request callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_SEND_INVITE_TO_FREIND:
// Send invite callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_ACCEPT_INVITE_FROM_FRIEND:
// Accept invite callback
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_ON_RELATIONSHIP_CHANGED:
// Notification for friend list changes, refresh list recommended
break;
case (int)INTLMethodID.INTL_FRIEND_DISCORD_ON_LOBBY_MEMBER_CHANGED:
// Notification for lobby member changes, refresh status recommended
break;
}
}

Personal Information Callback

INTLAPI.AddDiscordUserResultObserver(OnDiscordUserResult);
INTLAPI.RemoveDiscordUserResultObserver(OnDiscordUserResult);

private void OnDiscordUserResult(INTLDiscordUserResult userRet)
{
if (userRet.MethodId == (int)INTLMethodID.INTL_FRIEND_DISCORD_GET_CONNECTED_USER)
{
// Handle user info
}
}

Friend List Callback

INTLAPI.AddDiscordFriendsResultObserver(OnDiscordFriendResult);
INTLAPI.RemoveDiscordFriendsResultObserver(OnDiscordFriendResult);

private void OnDiscordFriendResult(INTLDiscordFriendResult friendRet)
{
// Handle friends list
}

Text Message Callback

INTLAPI.AddDiscordMessageResultObserver(OnDiscordMessageResult);
INTLAPI.RemoveDiscordMessageResultObserve(OnDiscordMessageResult);

private void OnDiscordMessageResult(INTLDiscordMessageResult messageRet)
{
// Handle message changes
}

Lobby Invitation Callback

INTLAPI.AddDiscordInviteResultObserver(OnDiscordInviteResult);
INTLAPI.RemoveDiscordInviteResultObserver(OnDiscordInviteResult);

private void OnDiscordInviteResult(INTLDiscordInviteResult inviteRet)
{
// Handle invitations
}

Step 3: Call the API

DiscordAuthorize

Function: Link Discord account and grant friend permissions

Linking process:

  • First time: Bring up authorization page → enter account and password → complete linking
  • Next time: Direct linking using cache (if devices are changed or app is reinstalled, reauthorization is required)
  • Unlink: Must be operated in-game (revoking authorization in Discord alone is not sufficient)
info

Must be called after every login and before invoking other Discord interfaces. Wait for callback to return SUCCESS before calling other functions.

The Discord authorization flow is shown below:

authorize flow

Reference style for Discord PC-side authorization page:

Image: Authorization Page

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordAuthorize();

IsAuthorized

Function: Check if a cached token exists locally

Use case: Prevent automatic launch of the authorization page

  • If returns true: directly call DiscordAuthorize()
  • If returns false: display a button for the user to manually authorize
bool isAuthorized = INTLAPI.IsAuthorized();

DiscordGetConnectedUser

Callback: DiscordUserResultObserver
Data: DiscordUserInfo

INTLAPI.DiscordGetConnectedUser();

DiscordQueryFriends

Parameters:

  • page (int): page number, >0
  • count (int): items per page, >0

Callback handling interface: DiscordFriendsResultObserver

INTLAPI.DiscordQueryFriends(1, 10);

DiscordAddFriendByName

Parameter: username (string)
Effect: The recipient can view the request; upon approval both parties receive friend list change callback

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordAddFriendByName("xiaoming");

DiscordAddFriendByID

Parameter: userId (string)
Effect: The recipient can view the request; upon approval both parties receive friend list change callback

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordAddFriendById("123456789");

DiscordAcceptFriendRequest

Parameter: userId (string) - applicant's ID
Effect: Both parties receive friend list change callback

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordAcceptFriendRequest("123456789");

DiscordRemoveFriend

Parameter: userId (string)
Effect: No approval needed; both parties receive friend list change callback

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordRemoveFriend("123456789");
Friend list change callback

After friend management functions succeed, both parties will receive the kMethodIDFriendDiscordOnRelationshipChanged callback.The callback does not contain userId; please call DiscordQueryFriends for details.

DiscordSendMessage

Parameters:

  • recipientId (string): Recipient ID
  • content (string): Message content

Sending rules:

  • Friend relationship: success
  • Never friends: failure
  • Previously friends, now deleted:
    • Recipient online: callback successful but not displayed
    • Recipient offline: error 50007
caution

Sending messages involves privacy; the game must disclose this.

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordSendMessage("123456789", "hello world!");
info

Registering Message Callback allows you to monitor friend message changes (create/edit/delete). Messages may contain emoji or non-text content.

DiscordSetRichPresence

Callback: DiscordBaseResultObserver
Parameter: DiscordRichPresence

INTLDiscordRichPresence richPresence = new INTLDiscordRichPresence();
richPresence.GameName = "Sample";
richPresence.State = "HappyTime";
richPresence.Details = "This is INTL Sample Game";
richPresence.PartyMaxSize = 5;
richPresence.SupportedPlatforms = 1 | 8 | 16;

INTLAPI.DiscordSetRichPresence(richPresence);

DiscordCreateLobby

Parameter: secret (string) - unique lobby identifier (valid for about 30 days)

Limitations:

  • A user can only be in one lobby at a time.
  • You must leave the current lobby before joining a new one.
  • Exiting the game does not automatically leave the lobby; an active call is required.
  • Lobby expires automatically several minutes after all members leave.

Recommendation: Encrypt the secret to prevent uninformed users from joining.

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordCreateLobby("testsecret");

DiscordLeaveLobby

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordLeaveLobby();
info

Whenever any member joins or leaves the lobby, all members will receive a callback.

DiscordSendInviteToFriend

Must be performed in order:

  1. Create Lobby
  2. Set game status
  3. Send Invite

The sending invite flow is shown below:

send invite and accept flow

Parameters:

  • userId (string): Friend ID
  • content (string): Invitation message

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordSendInviteToFriend("123456789", "hi, come to play with me");

DiscordAcceptInviteFromFriend

There are two ways to accept Discord game invitations:

Method 1: Function call
Register invitation callback, then invoke this function within the callback.

Method 2: Discord client

  • PC: Click Join to join automatically
  • Mobile: Click Join → DeepLink triggers the game → parse joinSecret → call DiscordCreateLobby

Parameter: userId (string) - sender ID

Callback handling interface: DiscordBaseResultObserver

INTLAPI.DiscordAcceptInviteFromFriend("123456789");