dfx 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DiscordREST/types.js +6 -0
- package/DiscordREST/types.js.map +1 -0
- package/DiscordWS/index.js +2 -0
- package/DiscordWS/index.js.map +1 -0
- package/README.md +3 -0
- package/WS/index.js +71 -0
- package/WS/index.js.map +1 -0
- package/discord-api-docs/index.js +1 -0
- package/mod.js.map +1 -0
- package/package.json +6 -1
- package/types.js +1563 -0
- package/types.js.map +1 -0
- package/websocket.js +11 -0
- package/websocket.js.map +1 -0
- package/.gitmodules +0 -3
- package/.prettierrc.json +0 -4
- package/discord-api-docs/.eslintrc.json +0 -10
- package/discord-api-docs/.gitattributes +0 -11
- package/discord-api-docs/.github/ISSUE_TEMPLATE/api-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/config.yml +0 -20
- package/discord-api-docs/.github/ISSUE_TEMPLATE/developer-site-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/message-components-bug-report.yml +0 -49
- package/discord-api-docs/.github/ISSUE_TEMPLATE/slash-command-bug-report.yml +0 -49
- package/discord-api-docs/.github/workflows/test.yaml +0 -45
- package/discord-api-docs/.prettierignore +0 -1
- package/discord-api-docs/.prettierrc.json +0 -15
- package/discord-api-docs/CODE_OF_CONDUCT.md +0 -75
- package/discord-api-docs/CONTRIBUTING.md +0 -16
- package/discord-api-docs/README.md +0 -35
- package/discord-api-docs/docs/Change_Log.md +0 -474
- package/discord-api-docs/docs/Intro.md +0 -48
- package/discord-api-docs/docs/Legal.md +0 -154
- package/discord-api-docs/docs/Policy.md +0 -81
- package/discord-api-docs/docs/Reference.md +0 -476
- package/discord-api-docs/docs/Store_Distribution_Agreement.md +0 -179
- package/discord-api-docs/docs/dispatch/Branches_and_Builds.md +0 -654
- package/discord-api-docs/docs/dispatch/Dispatch_and_You.md +0 -17
- package/discord-api-docs/docs/dispatch/Error_Codes.md +0 -26
- package/discord-api-docs/docs/dispatch/Field_Values.md +0 -48
- package/discord-api-docs/docs/dispatch/List_of_Commands.md +0 -315
- package/discord-api-docs/docs/game_and_server_management/Alpha_and_Beta_Testing.md +0 -52
- package/discord-api-docs/docs/game_and_server_management/How_to_Get_Your_Game_on_Discord.md +0 -110
- package/discord-api-docs/docs/game_and_server_management/Special_Channels.md +0 -38
- package/discord-api-docs/docs/game_sdk/Achievements.md +0 -405
- package/discord-api-docs/docs/game_sdk/Activities.md +0 -561
- package/discord-api-docs/docs/game_sdk/Applications.md +0 -237
- package/discord-api-docs/docs/game_sdk/Discord.md +0 -443
- package/discord-api-docs/docs/game_sdk/Discord_Voice.md +0 -289
- package/discord-api-docs/docs/game_sdk/Images.md +0 -196
- package/discord-api-docs/docs/game_sdk/Lobbies.md +0 -1639
- package/discord-api-docs/docs/game_sdk/Networking.md +0 -377
- package/discord-api-docs/docs/game_sdk/Overlay.md +0 -195
- package/discord-api-docs/docs/game_sdk/Relationships.md +0 -234
- package/discord-api-docs/docs/game_sdk/SDK_Starter_Guide.md +0 -310
- package/discord-api-docs/docs/game_sdk/Storage.md +0 -312
- package/discord-api-docs/docs/game_sdk/Store.md +0 -555
- package/discord-api-docs/docs/game_sdk/Users.md +0 -178
- package/discord-api-docs/docs/interactions/Application_Commands.md +0 -1069
- package/discord-api-docs/docs/interactions/Message_Components.md +0 -454
- package/discord-api-docs/docs/interactions/Receiving_and_Responding.md +0 -372
- package/discord-api-docs/docs/interactions/Slash_Commands.md +0 -3
- package/discord-api-docs/docs/resources/Application.md +0 -82
- package/discord-api-docs/docs/resources/Audit_Log.md +0 -223
- package/discord-api-docs/docs/resources/Channel.md +0 -1267
- package/discord-api-docs/docs/resources/Emoji.md +0 -122
- package/discord-api-docs/docs/resources/Guild.md +0 -1157
- package/discord-api-docs/docs/resources/Guild_Scheduled_Event.md +0 -273
- package/discord-api-docs/docs/resources/Guild_Template.md +0 -148
- package/discord-api-docs/docs/resources/Invite.md +0 -150
- package/discord-api-docs/docs/resources/Stage_Instance.md +0 -106
- package/discord-api-docs/docs/resources/Sticker.md +0 -164
- package/discord-api-docs/docs/resources/User.md +0 -205
- package/discord-api-docs/docs/resources/Voice.md +0 -55
- package/discord-api-docs/docs/resources/Webhook.md +0 -281
- package/discord-api-docs/docs/rich_presence/Best_Practices.md +0 -88
- package/discord-api-docs/docs/rich_presence/FAQ.md +0 -45
- package/discord-api-docs/docs/rich_presence/How_To.md +0 -302
- package/discord-api-docs/docs/rich_presence/Launch_Checklist.md +0 -46
- package/discord-api-docs/docs/topics/Certified_Devices.md +0 -200
- package/discord-api-docs/docs/topics/Community_Resources.md +0 -98
- package/discord-api-docs/docs/topics/Gateway.md +0 -1600
- package/discord-api-docs/docs/topics/OAuth2.md +0 -427
- package/discord-api-docs/docs/topics/Opcodes_and_Status_Codes.md +0 -306
- package/discord-api-docs/docs/topics/Permissions.md +0 -229
- package/discord-api-docs/docs/topics/RPC.md +0 -1597
- package/discord-api-docs/docs/topics/Rate_Limits.md +0 -126
- package/discord-api-docs/docs/topics/Teams.md +0 -80
- package/discord-api-docs/docs/topics/Threads.md +0 -163
- package/discord-api-docs/docs/topics/Voice_Connections.md +0 -282
- package/discord-api-docs/images/API_center.gif +0 -0
- package/discord-api-docs/images/ask-to-join.gif +0 -0
- package/discord-api-docs/images/available-published.png +0 -0
- package/discord-api-docs/images/button-styles.png +0 -0
- package/discord-api-docs/images/certified-device.png +0 -0
- package/discord-api-docs/images/command-with-groups-subcommands-parameters.png +0 -0
- package/discord-api-docs/images/command-with-groups-subcommands.png +0 -0
- package/discord-api-docs/images/command.png +0 -0
- package/discord-api-docs/images/cpp-files-sdk.png +0 -0
- package/discord-api-docs/images/create-store-channel.png +0 -0
- package/discord-api-docs/images/deferred-example.png +0 -0
- package/discord-api-docs/images/desktop-select.png +0 -0
- package/discord-api-docs/images/game-overlay-sdk-invite.gif +0 -0
- package/discord-api-docs/images/game-overlay-sdk-voice-settings.png +0 -0
- package/discord-api-docs/images/game-overlay-sdk-voice-widget.png +0 -0
- package/discord-api-docs/images/gift-code-creation.png +0 -0
- package/discord-api-docs/images/lib-linked-sdk.png +0 -0
- package/discord-api-docs/images/message-command.png +0 -0
- package/discord-api-docs/images/mobile-select.png +0 -0
- package/discord-api-docs/images/previous-new-server-background.png +0 -0
- package/discord-api-docs/images/rp-actionable.png +0 -0
- package/discord-api-docs/images/rp-all-fields.png +0 -0
- package/discord-api-docs/images/rp-bad-art.png +0 -0
- package/discord-api-docs/images/rp-good-art.png +0 -0
- package/discord-api-docs/images/rp-legend.png +0 -0
- package/discord-api-docs/images/rp-long-strings.png +0 -0
- package/discord-api-docs/images/rp-non-actionable.png +0 -0
- package/discord-api-docs/images/rp-not-all-fields.png +0 -0
- package/discord-api-docs/images/rp-profile-example-1.png +0 -0
- package/discord-api-docs/images/rp-profile-example-2.png +0 -0
- package/discord-api-docs/images/rp-short-strings.png +0 -0
- package/discord-api-docs/images/server-banner-example.png +0 -0
- package/discord-api-docs/images/server-banner-margin-top.png +0 -0
- package/discord-api-docs/images/sku-management.png +0 -0
- package/discord-api-docs/images/snowflake.png +0 -0
- package/discord-api-docs/images/snowflake_original_size.png +0 -0
- package/discord-api-docs/images/spectate.gif +0 -0
- package/discord-api-docs/images/team-2fa.png +0 -0
- package/discord-api-docs/images/team-make-app.png +0 -0
- package/discord-api-docs/images/team-page.png +0 -0
- package/discord-api-docs/images/transfer-app-to-team.png +0 -0
- package/discord-api-docs/images/user-command.png +0 -0
- package/discord-api-docs/package-lock.json +0 -3186
- package/discord-api-docs/package.json +0 -38
- package/discord-api-docs/tsconfig.eslint.json +0 -4
- package/discord-api-docs/tsconfig.json +0 -19
- package/tsconfig.json +0 -24
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
# Relationships
|
|
2
|
-
|
|
3
|
-
> info
|
|
4
|
-
> Need help with the SDK? Talk to us in the [Discord Developers Server](https://discord.gg/discord-developers)!
|
|
5
|
-
|
|
6
|
-
> danger
|
|
7
|
-
> Selling SKUs on Discord is now deprecated, and will be discontinued on March 1, 2022. [Read here for more info.](https://support-dev.discord.com/hc/en-us/articles/4414590563479)
|
|
8
|
-
|
|
9
|
-
This manager helps you access the relationships your players have made on Discord. Unfortunately, it won't help them make relationships IRL. They're on their own for that. It lets you:
|
|
10
|
-
|
|
11
|
-
- Access a user's relationships
|
|
12
|
-
- Filter those relationships based on a given criteria
|
|
13
|
-
- Build a user's friends list
|
|
14
|
-
|
|
15
|
-
## First Notes
|
|
16
|
-
|
|
17
|
-
Relationships on Discord change often; people start and stop playing games, go online, offline, invisible, or otherwise change state. Therefore, there are some important factors to remember when working with this manager. When you are first getting a list of a user's relationships, before you can `Filter()`, you need to wait for the `OnRefresh` callback to fire. This is your indicator that Discord has successfully taken a snapshot of the state of all your relationships at a given moment. Now that you have this snapshot, you can `Filter()` it to build the list that you want, and then iterate over that list to do whatever your game needs to do. Use this to build your initial social graph for a user.
|
|
18
|
-
|
|
19
|
-
As relationships change, the `OnRelationshipUpdate` event will fire. You can use this to update the user's social graph, changing the status of the other Discord users that you chose to filter, e.g. someone is now online, or now playing the game, or no longer playing.
|
|
20
|
-
|
|
21
|
-
An example of how to do this properly is at the end of this documentation page.
|
|
22
|
-
|
|
23
|
-
## Data Models
|
|
24
|
-
|
|
25
|
-
###### Relationship Struct
|
|
26
|
-
|
|
27
|
-
| name | type | description |
|
|
28
|
-
| -------- | ---------------- | -------------------------------- |
|
|
29
|
-
| Type | RelationshipType | what kind of relationship it is |
|
|
30
|
-
| User | User | the user the relationship is for |
|
|
31
|
-
| Presence | Presence | that user's current presence |
|
|
32
|
-
|
|
33
|
-
###### RelationshipType Enum
|
|
34
|
-
|
|
35
|
-
| value | description |
|
|
36
|
-
| --------------- | -------------------------------------------------------------------------------- |
|
|
37
|
-
| None | user has no intrinsic relationship |
|
|
38
|
-
| Friend | user is a friend |
|
|
39
|
-
| Blocked | user is blocked |
|
|
40
|
-
| PendingIncoming | user has a pending incoming friend request to connected user |
|
|
41
|
-
| PendingOutgoing | current user has a pending outgoing friend request to user |
|
|
42
|
-
| Implicit | user is not friends, but interacts with current user often (frequency + recency) |
|
|
43
|
-
|
|
44
|
-
###### Presence Struct
|
|
45
|
-
|
|
46
|
-
| name | type | description |
|
|
47
|
-
| -------- | -------- | -------------------------------- |
|
|
48
|
-
| Status | Status | the user's current online status |
|
|
49
|
-
| Activity | Activity | the user's current activity |
|
|
50
|
-
|
|
51
|
-
###### Status Enum
|
|
52
|
-
|
|
53
|
-
| name | value |
|
|
54
|
-
| ------------ | ----- |
|
|
55
|
-
| Offline | 0 |
|
|
56
|
-
| Online | 1 |
|
|
57
|
-
| Idle | 2 |
|
|
58
|
-
| DoNotDisturb | 3 |
|
|
59
|
-
|
|
60
|
-
## Filter
|
|
61
|
-
|
|
62
|
-
Filters a user's relationship list by a boolean condition.
|
|
63
|
-
|
|
64
|
-
Returns `void`.
|
|
65
|
-
|
|
66
|
-
###### Parameters
|
|
67
|
-
|
|
68
|
-
A function that takes a `Relationship` parameter.
|
|
69
|
-
|
|
70
|
-
###### Example
|
|
71
|
-
|
|
72
|
-
```cs
|
|
73
|
-
relationshipsManager.Filter(relationship =>
|
|
74
|
-
{
|
|
75
|
-
return relationship.Presence.Status == Discord.Status.Online;
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Get
|
|
80
|
-
|
|
81
|
-
Get the relationship between the current user and a given user by id.
|
|
82
|
-
|
|
83
|
-
Returns a `Relationship`.
|
|
84
|
-
|
|
85
|
-
###### Parameters
|
|
86
|
-
|
|
87
|
-
| name | type | description |
|
|
88
|
-
| ------ | ----- | --------------------------- |
|
|
89
|
-
| userId | Int64 | the id of the user to fetch |
|
|
90
|
-
|
|
91
|
-
###### Example
|
|
92
|
-
|
|
93
|
-
```cs
|
|
94
|
-
var friend = relationshipsManager.Get(53908232506183680);
|
|
95
|
-
Console.WriteLine("This is my friend, {0}", friend.User.Username);
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## GetAt
|
|
99
|
-
|
|
100
|
-
Get the relationship at a given index when iterating over a list of relationships.
|
|
101
|
-
|
|
102
|
-
Returns a `Relationship`.
|
|
103
|
-
|
|
104
|
-
###### Parameters
|
|
105
|
-
|
|
106
|
-
| name | type | description |
|
|
107
|
-
| ----- | ------ | ----------------- |
|
|
108
|
-
| index | UInt32 | index in the list |
|
|
109
|
-
|
|
110
|
-
###### Example
|
|
111
|
-
|
|
112
|
-
```cs
|
|
113
|
-
for (int i = 0; i < relationshipsManager.Count(); i++)
|
|
114
|
-
{
|
|
115
|
-
var r = relationshipsManager.GetAt(i);
|
|
116
|
-
Console.WriteLine("This person is {0}", r.User.Username);
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## Count
|
|
121
|
-
|
|
122
|
-
Get the number of relationships that match your `Filter()`.
|
|
123
|
-
|
|
124
|
-
Returns an `Int32`.
|
|
125
|
-
|
|
126
|
-
###### Parameters
|
|
127
|
-
|
|
128
|
-
None
|
|
129
|
-
|
|
130
|
-
###### Example
|
|
131
|
-
|
|
132
|
-
```cs
|
|
133
|
-
for (int i = 0; i < relationshipsManager.Count(); i++)
|
|
134
|
-
{
|
|
135
|
-
var r = relationshipsManager.At(i);
|
|
136
|
-
Console.WriteLine("This person is {0}", r.User.Username);
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## OnRefresh
|
|
141
|
-
|
|
142
|
-
Fires at initialization when Discord has cached a snapshot of the current status of all your relationships. Wait for this to fire before calling `Filter` within its callback.
|
|
143
|
-
|
|
144
|
-
###### Parameters
|
|
145
|
-
|
|
146
|
-
None
|
|
147
|
-
|
|
148
|
-
## OnRelationshipUpdate
|
|
149
|
-
|
|
150
|
-
Fires when a relationship in the filtered list changes, like an updated presence or user attribute.
|
|
151
|
-
|
|
152
|
-
###### Parameters
|
|
153
|
-
|
|
154
|
-
| name | type | description |
|
|
155
|
-
| ------------ | ---------------- | ----------------------------- |
|
|
156
|
-
| relationship | ref Relationship | the relationship that changed |
|
|
157
|
-
|
|
158
|
-
###### Example
|
|
159
|
-
|
|
160
|
-
```cs
|
|
161
|
-
OnRelationshipUpdate += (ref Discord.Relationship relationship) =>
|
|
162
|
-
{
|
|
163
|
-
Console.WriteLine("Who changed? {0}", relationship.User.Id);
|
|
164
|
-
};
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Example: Creating a Friends List
|
|
168
|
-
|
|
169
|
-
```cs
|
|
170
|
-
var discord = new Discord.Discord(clientId, Discord.CreateFlags.Default);
|
|
171
|
-
var relationshipManager = discord.GetRelationshipManager();
|
|
172
|
-
|
|
173
|
-
// Assign this handle right away to get the initial relationships update.
|
|
174
|
-
// This callback will only be fired when the whole list is initially loaded or was reset
|
|
175
|
-
|
|
176
|
-
// Wait for OnRefresh to fire to access a stable list
|
|
177
|
-
// Filter a user's relationship list to be just friends
|
|
178
|
-
// Use this list as your base
|
|
179
|
-
relationshipManager.OnRefresh += () =>
|
|
180
|
-
{
|
|
181
|
-
relationshipManager.Filter((relationship) =>
|
|
182
|
-
{
|
|
183
|
-
return relationship.Type == Discord.RelationshipType.Friend;
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Loop over all friends a user has.
|
|
187
|
-
Console.WriteLine("relationships updated: {0}", relationshipManager.Count());
|
|
188
|
-
|
|
189
|
-
for (var i = 0; i < relationshipManager.Count(); i++)
|
|
190
|
-
{
|
|
191
|
-
// Get an individual relationship from the list
|
|
192
|
-
var r = relationshipManager.GetAt((uint)i);
|
|
193
|
-
Console.WriteLine("relationships: {0} {1}", r.Type, r.User.Username);
|
|
194
|
-
// Save r off to a list of user's relationships
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
relationshipManager.OnRelationshipUpdate += (ref Discord.Relationship relationship) =>
|
|
199
|
-
{
|
|
200
|
-
Console.WriteLine("User is {0}", relationship.User.Username);
|
|
201
|
-
// Update the matching user in your previously created list
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## Example: Invite Users Who Are Playing the Same Game
|
|
206
|
-
|
|
207
|
-
```cs
|
|
208
|
-
var discord = new Discord.Discord(clientId, Discord.CreateFlags.Default);
|
|
209
|
-
var relationshipManager = discord.GetRelationshipManager();
|
|
210
|
-
var activityManager = discord.GetActivityManager();
|
|
211
|
-
|
|
212
|
-
relationshipManager.OnRefresh += () =>
|
|
213
|
-
{
|
|
214
|
-
relationshipManager.Filter((relationship) =>
|
|
215
|
-
{
|
|
216
|
-
// Filter for users who are playing the same game as the current user
|
|
217
|
-
// Is their activity application id the same as my client id?
|
|
218
|
-
return relationship.Presence.Activity.ApplicationId == clientId;
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
for (var i = 0; i < relationshipManager.Count(); i++)
|
|
222
|
-
{
|
|
223
|
-
// Get an individual relationship from the list
|
|
224
|
-
var r = relationshipManager.GetAt((uint)i);
|
|
225
|
-
Console.WriteLine("relationships: {0} {1}", r.Type, r.User.Username);
|
|
226
|
-
|
|
227
|
-
// Send them a game invite!
|
|
228
|
-
activityManager.InviteUser(r.User.Id, Discord.ActivityActionType.Join, "Come play with me!", (result) =>
|
|
229
|
-
{
|
|
230
|
-
Console.WriteLine("Invited user {0} to play with you", r.User.Username);
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
```
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
# SDK Starter Guide
|
|
2
|
-
|
|
3
|
-
> info
|
|
4
|
-
> Need help with the SDK? Talk to us in the [Discord Developers Server](https://discord.gg/discord-developers)!
|
|
5
|
-
|
|
6
|
-
> danger
|
|
7
|
-
> Selling SKUs on Discord is now deprecated, and will be discontinued on March 1, 2022. [Read here for more info.](https://support-dev.discord.com/hc/en-us/articles/4414590563479)
|
|
8
|
-
|
|
9
|
-
Welcome to the Discord GameSDK! We're glad you made it. This SDK is here to solve all your problems, if your problems include finding an awesome SDK to help develop your game. Our SDK is like Clippy, if Clippy were built on a modern tech stack, talked less, and was an awesome game development SDK.
|
|
10
|
-
|
|
11
|
-
## Step 0 - Some Notes
|
|
12
|
-
|
|
13
|
-
Before we get off to the races, a couple notes on the SDK:
|
|
14
|
-
|
|
15
|
-
- All strings in the SDK are UTF8 strings
|
|
16
|
-
- Make sure you've converted properly if necessary!
|
|
17
|
-
- The SDK is **_NOT_** threadsafe!
|
|
18
|
-
- Being callback-based, we thought that'd be confusing and inconsistent
|
|
19
|
-
|
|
20
|
-
Now you know, and knowing is half the battle.
|
|
21
|
-
|
|
22
|
-
## Step 1 - Get the Thing
|
|
23
|
-
|
|
24
|
-
I know you're already convinced, so let's begin. First, get the SDK. Here it is:
|
|
25
|
-
|
|
26
|
-
- [Discord Game SDK](https://dl-game-sdk.discordapp.net/2.5.6/discord_game_sdk.zip)
|
|
27
|
-
|
|
28
|
-
There's a few things in there, but let's quickly talk about what the SDK actually _is_. Inside the `lib/` folder, you'll see `x86/` and `x86_64/` that have some `.lib`, `.bundle`, and `.dll` files. These are the things you want to distribute with your game.
|
|
29
|
-
|
|
30
|
-
These files are comprised of two parts: a "stub", and fallback modules. What that means is that when everything is running smoothly, the DLLs will just call back to the local running Discord client to do the heavy lifting. If, however, something is wrong, like a breaking change, the files also include "fallback" modules that reflect the native SDK modules in Discord at the time that version of the SDK was published. TLDR - you don't need to worry about breaking changes.
|
|
31
|
-
|
|
32
|
-
## Get Set Up
|
|
33
|
-
|
|
34
|
-
Next, we need to set up the application for your game. An application is the base "entity" in Discord for your game; it's what all the builds, branches, SKUs, store pages, assets, etc. will be filed under.
|
|
35
|
-
|
|
36
|
-
Head over to our [developer site](https://discord.com/developers/) and create an account/log in if you haven't yet. The first thing we're going to do is create a Team. Teams are groups of developers working together on applications; you should create a team for your organization at [https://discord.com/developers/teams](https://discord.com/developers/teams). You can invite other users to join your team and work on applications together with you.
|
|
37
|
-
|
|
38
|
-
Now that your team is created, you'll want to make an application. To do so, click on "Applications" at the top of the page and create an application. Make sure you pick your newly-created team in the `Team` dropdown. You want your team to own the application; this unlocks store functionality! Now that your app is made, let's dive into some more setup.
|
|
39
|
-
|
|
40
|
-
> warn
|
|
41
|
-
> If you're integrating our SDK into an already-released game, there's a good chance that we may _already have_ an application in our database for your game! Reach out to our [Dev Support](https://dis.gd/devsupport) to learn more
|
|
42
|
-
|
|
43
|
-
First, we'll need to set an OAuth2 redirect URL. You can add `http://127.0.0.1` in there for now; this powers some behind-the-scenes stuff you don't need to worry about.
|
|
44
|
-
|
|
45
|
-
Next, copy the **Client ID** at the top of the page. This id, also referred to as an "application id", is your game's unique identifier across Discord. Keep it handy!
|
|
46
|
-
|
|
47
|
-
While you're here, head to the "OAuth2" section of your application and add `http://127.0.0.1` as a redirect URI for your application. This will allow us to do the OAuth2 token exchange within the Discord client.
|
|
48
|
-
|
|
49
|
-
Now we're gonna start coding. Didn't think we'd get there so fast, did ya? _Think again!_ The next sections are code primers for the main languages of the SDK: C#, C, and C++. They'll get you up and running with the most basic examples, and then you're off to the races.
|
|
50
|
-
|
|
51
|
-
## Code Primer - Unity (Csharp)
|
|
52
|
-
|
|
53
|
-
- Open up that SDK zip that you downloaded.
|
|
54
|
-
- Copy the contents of the `lib/` folder to `Assets/Plugins` in your Unity project
|
|
55
|
-
- Copy the contents of the `csharp/` folder to `Assets/Plugins/DiscordGameSDK`
|
|
56
|
-
|
|
57
|
-
From there, you'll be able to reference functions in the DLL within your scripts. A basic example of a script can be found [in this example repo](https://github.com/msciotti/discord-game-sdk-test-apps/tree/master/cs-examples/unity-examples/Assets). In this example, we attach our `DiscordController.cs` script to the Main Camera object of the default created scene. We then instantiate the SDK with:
|
|
58
|
-
|
|
59
|
-
```cs
|
|
60
|
-
/*
|
|
61
|
-
Grab that Client ID from earlier
|
|
62
|
-
Discord.CreateFlags.Default will require Discord to be running for the game to work
|
|
63
|
-
If Discord is not running, it will:
|
|
64
|
-
1. Close your game
|
|
65
|
-
2. Open Discord
|
|
66
|
-
3. Attempt to re-open your game
|
|
67
|
-
Step 3 will fail when running directly from the Unity editor
|
|
68
|
-
Therefore, always keep Discord running during tests, or use Discord.CreateFlags.NoRequireDiscord
|
|
69
|
-
*/
|
|
70
|
-
var discord = new Discord.Discord(CLIENT_ID, (UInt64)Discord.CreateFlags.Default);
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
You're now free to use other functionality in the SDK! Make sure to call `discord.RunCallbacks()` in your main game loop; that's your `Update()` function.
|
|
74
|
-
|
|
75
|
-
You're ready to go! Check out the rest of the documentation for more info on how to use the other pieces of the SDK. See an example of everything it can do in `examples/Program.cs` in the SDK zip file.
|
|
76
|
-
|
|
77
|
-
## Code Primer - Non-Unity Projects (Csharp)
|
|
78
|
-
|
|
79
|
-
- Open up that SDK zip that you downloaded.
|
|
80
|
-
- Create a folder in your project directory called `DiscordGameSDK` and copy the contents of the `csharp/` folder to it
|
|
81
|
-
- Build your solution then place the `.dll` in the directory of the `.exe` (either x86 or x86_64 version depending on your compile platform). If you compile for Any CPU you may need to perform additional wrapping around DLL importing (like setting the DLL directory dynamically) to make sure you load the correct DLL.
|
|
82
|
-
|
|
83
|
-
From there, you'll be able to reference functions in the DLL within your scripts. We then instantiate the SDK with:
|
|
84
|
-
|
|
85
|
-
```cs
|
|
86
|
-
/*
|
|
87
|
-
Grab that Client ID from earlier
|
|
88
|
-
Discord.CreateFlags.Default will require Discord to be running for the game to work
|
|
89
|
-
If Discord is not running, it will:
|
|
90
|
-
1. Close your game
|
|
91
|
-
2. Open Discord
|
|
92
|
-
3. Attempt to re-open your game
|
|
93
|
-
Step 3 may fail when running directly from your editor
|
|
94
|
-
Therefore, always keep Discord running during tests, or use Discord.CreateFlags.NoRequireDiscord
|
|
95
|
-
*/
|
|
96
|
-
var discord = new Discord.Discord(CLIENT_ID, (UInt64)Discord.CreateFlags.Default);
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
You're now free to use other functionality in the SDK! Make sure to call `discord.RunCallbacks()` in your main game loop; that's your `Update()` function.
|
|
100
|
-
|
|
101
|
-
You're ready to go! Check out the rest of the documentation for more info on how to use the other pieces of the SDK. See an example of everything it can do in `examples/Program.cs` in the SDK zip file.
|
|
102
|
-
|
|
103
|
-
## Code Primer - Unreal Engine (C)
|
|
104
|
-
|
|
105
|
-
Before jumping into the C binding, a word of caution. If you are using Unreal Engine 3, or need to support an older version of Visual Studio, you may at first see some unexpected crashes due to compile configurations. The way to fix this is to wrap the include statement for the Discord GameSDK header file like so:
|
|
106
|
-
|
|
107
|
-
```c
|
|
108
|
-
#pragma pack(push, 8)
|
|
109
|
-
#include "discord_game_sdk.h"
|
|
110
|
-
#pragma pack(pop)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
This should let you use the SDK without any further crashes. Now, on with the show!
|
|
114
|
-
|
|
115
|
-
- Open up that SDK zip that you downloaded.
|
|
116
|
-
- Copy the contents of the `lib/` folder to the best location within your project for DLLs.
|
|
117
|
-
- Copy the contents of the `c/` folder to your source directory
|
|
118
|
-
- It's dangerous to go alone—take this small code block with you (to start)!
|
|
119
|
-
|
|
120
|
-
```c
|
|
121
|
-
struct Application {
|
|
122
|
-
struct IDiscordCore* core;
|
|
123
|
-
struct IDiscordUsers* users;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
struct Application app;
|
|
127
|
-
// Don't forget to memset or otherwise initialize your classes!
|
|
128
|
-
memset(&app, 0, sizeof(app));
|
|
129
|
-
|
|
130
|
-
struct IDiscordCoreEvents events;
|
|
131
|
-
memset(&events, 0, sizeof(events));
|
|
132
|
-
|
|
133
|
-
struct DiscordCreateParams params;
|
|
134
|
-
params.client_id = CLIENT_ID;
|
|
135
|
-
params.flags = DiscordCreateFlags_Default;
|
|
136
|
-
params.events = &events;
|
|
137
|
-
params.event_data = &app;
|
|
138
|
-
|
|
139
|
-
DiscordCreate(DISCORD_VERSION, ¶ms, &app.core);
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
- Make sure to call `core->run_callbacks(core, 0)` in your game loop.
|
|
143
|
-
|
|
144
|
-
You're ready to go! Check out the rest of the documentation for more info on how to use the other pieces of the SDK. See an example of everything it can do in `examples/c/main.c` in the SDK zip file.
|
|
145
|
-
|
|
146
|
-
## Code Primer - Unreal Engine 4 (Cpp)
|
|
147
|
-
|
|
148
|
-
Open up that SDK zip that you downloaded. There's a couple things in there that we care about. The first is the contents of the `cpp/` folder. These are our source files, including headers and `.cpp` file, that we'll need to reference in our build script. Second is the contents of the `lib/` folder. In this walkthrough we'll assume that we only care about win64, for ease of use.
|
|
149
|
-
|
|
150
|
-
First, you'll want to copy the header files and `.cpp` files to a folder somewhere in your project directory. For ease of a quickstart example, you can put them right inside your `Source/your-project-name` folder; I'd put them in a containing folder called something like `discord-files/`.
|
|
151
|
-
|
|
152
|
-
Second, you'll want to copy the `.dll` and `.lib` files from the `lib/x86_64` folder of the downloaded zip. These files should be put in `your-project-name/Binaries/Win64/`. For win32, take the files from `x86/` and put them, in `your-project-name/Binaries/Win32`.
|
|
153
|
-
|
|
154
|
-
Next, we need to link these files within our project so that we can reference them. If you open up your project's `.sln` file in Visual Studio, you'll find a file called `your-project-name.Build.cs`. We're going to add the following lines of code to that file:
|
|
155
|
-
|
|
156
|
-
```cpp
|
|
157
|
-
/*
|
|
158
|
-
ABSOLUTE_PATH_TO_DISCORD_FILES_DIRECTORY will look something like:
|
|
159
|
-
|
|
160
|
-
"H:\\Unreal Projects\\gamesdktest\\Source\\gamesdktest\\discord-files\\"
|
|
161
|
-
|
|
162
|
-
You should get this value programmatically
|
|
163
|
-
*/
|
|
164
|
-
PublicIncludePaths.Add(ABSOLUTE_PATH_TO_DISCORD_FILES_DIRECTORY)
|
|
165
|
-
|
|
166
|
-
/*
|
|
167
|
-
ABSOLUTE_PATH_TO_LIB_FILE will look something like:
|
|
168
|
-
|
|
169
|
-
"H:\\Unreal Projects\\gamesdktest\\Binaries\\Win64\\discord_game_sdk.dll.lib"
|
|
170
|
-
|
|
171
|
-
You should get this value programmatically
|
|
172
|
-
*/
|
|
173
|
-
PublicAdditionalLibraries.Add(ABSOLUTE_PATH_TO_LIB_FILE)
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Now that we've got our new dependencies properly linked, we can reference them in our code. In this example, we're going to make a new `Pawn` class called `MyPawn`. It will look something like this:
|
|
177
|
-
|
|
178
|
-
```cpp
|
|
179
|
-
#include "MyPawn.h"
|
|
180
|
-
#include "discord-files/discord.h"
|
|
181
|
-
|
|
182
|
-
discord::Core* core{};
|
|
183
|
-
|
|
184
|
-
AMyPawn::AMyPawn()
|
|
185
|
-
{
|
|
186
|
-
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
187
|
-
PrimaryActorTick.bCanEverTick = true;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Called when the game starts or when spawned
|
|
191
|
-
void AMyPawn::BeginPlay()
|
|
192
|
-
{
|
|
193
|
-
Super::BeginPlay();
|
|
194
|
-
/*
|
|
195
|
-
Grab that Client ID from earlier
|
|
196
|
-
Discord.CreateFlags.Default will require Discord to be running for the game to work
|
|
197
|
-
If Discord is not running, it will:
|
|
198
|
-
1. Close your game
|
|
199
|
-
2. Open Discord
|
|
200
|
-
3. Attempt to re-open your game
|
|
201
|
-
Step 3 will fail when running directly from the Unreal Engine editor
|
|
202
|
-
Therefore, always keep Discord running during tests, or use Discord.CreateFlags.NoRequireDiscord
|
|
203
|
-
*/
|
|
204
|
-
auto result = discord::Core::Create(461618159171141643, DiscordCreateFlags_Default, &core);
|
|
205
|
-
discord::Activity activity{};
|
|
206
|
-
activity.SetState("Testing");
|
|
207
|
-
activity.SetDetails("Fruit Loops");
|
|
208
|
-
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Called every frame
|
|
214
|
-
void AMyPawn::Tick(float DeltaTime)
|
|
215
|
-
{
|
|
216
|
-
Super::Tick(DeltaTime);
|
|
217
|
-
::core->RunCallbacks();
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Called to bind functionality to input
|
|
221
|
-
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
|
222
|
-
{
|
|
223
|
-
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
|
224
|
-
}
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
Make sure you've got `core->RunCallbacks()` going every frame!
|
|
228
|
-
|
|
229
|
-
You're ready to go! Check out the rest of the documentation for more info on how to use the other pieces of the SDK. See an example of everything it can do in `examples/cpp/main.cpp` in the SDK zip file.
|
|
230
|
-
|
|
231
|
-
## Code Primer - No Engine (Cpp)
|
|
232
|
-
|
|
233
|
-
In your project folder, you'll want to make something like a "discord-files" folder, for organization. In that folder, copy all the `.h` and `.cpp` files from the zip.
|
|
234
|
-
You want to include all the header and source files respectively in your project
|
|
235
|
-
|
|
236
|
-

|
|
237
|
-
|
|
238
|
-
In your project settings, you'll want to include the relevant library (e.g. `discord_game_sdk.dll.lib`) as an additional dependency.
|
|
239
|
-
|
|
240
|
-

|
|
241
|
-
|
|
242
|
-
- From there, you should be able to `#include "discord-files/discord.h"`, or whatever the path to that header file is, and have access to the code.
|
|
243
|
-
|
|
244
|
-
## Testing Locally with Two Clients
|
|
245
|
-
|
|
246
|
-
> info
|
|
247
|
-
> Value from environment variable `DISCORD_INSTANCE_ID`
|
|
248
|
-
|
|
249
|
-
While integrating the Discord GameSDK, you will probably find yourself wanting to test functionality between two game clients locally, be it for networking, Rich Presence, etc.
|
|
250
|
-
|
|
251
|
-
We also know that getting a test build of a game on two separate machines can be both difficult and cumbersome. So, we've got a solution for you! By using system environment variables, you can tell the SDK in a certain game client to connect to a specific Discord client. Here's how it works:
|
|
252
|
-
|
|
253
|
-
1. Download Discord Canary. This is our most updated build, and is good to develop against: [Windows](https://discord.com/api/download/canary?platform=win) - [Mac](https://discord.com/api/download/canary?platform=osx)
|
|
254
|
-
2. Download a second Discord Build. Here's our Public Test Build: [Windows](https://discord.com/api/download/ptb?platform=win) - [Mac](https://discord.com/api/download/ptb?platform=osx)
|
|
255
|
-
3. Open up two Discord clients. We recommend you develop against Discord Canary, so you can use PTB or Stable for your test account
|
|
256
|
-
4. Log in with two separate users. Make sure any test account is added to the application's App Whitelist in the portal!
|
|
257
|
-
|
|
258
|
-
Now, in your game code, you can tell the SDK which client to connect to via the environment variable `DISCORD_INSTANCE_ID` **before initializing the SDK**. The value of the variable corresponds to the order in which you opened the clients, so `0` would connect to the first opened client, `1` the second, etc.
|
|
259
|
-
|
|
260
|
-
###### Environment Variable Example
|
|
261
|
-
|
|
262
|
-
```cs
|
|
263
|
-
// This machine opened Discord Canary first, and Discord PTB second
|
|
264
|
-
|
|
265
|
-
// This makes the SDK connect to Canary
|
|
266
|
-
System.Environment.SetEnvironmentVariable("DISCORD_INSTANCE_ID", "0");
|
|
267
|
-
var discord = new Discord(applicationId, Discord.CreateFlags.Default);
|
|
268
|
-
|
|
269
|
-
// This makes the SDK connect to PTB
|
|
270
|
-
System.Environment.SetEnvironmentVariable("DISCORD_INSTANCE_ID", "1");
|
|
271
|
-
var discord = new Discord(applicationId, Discord.CreateFlags.Default);
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
This will set the environment variable only within the context of the running process, so don't worry about messing up global stuff.
|
|
275
|
-
|
|
276
|
-
> danger
|
|
277
|
-
> If you test with this, make sure to remove this code before pushing a production build. It will interfere with the way that Discord launches games for users.
|
|
278
|
-
|
|
279
|
-
## Section Checklist
|
|
280
|
-
|
|
281
|
-
Think of these like those end of section review pages from your history textbooks, but we won't give you a pop quiz. I promise. By now, you should have the following:
|
|
282
|
-
|
|
283
|
-
- The SDK downloaded
|
|
284
|
-
- An application created, and a Client ID you're keeping handy
|
|
285
|
-
- Rich Presence enabled on that application
|
|
286
|
-
- An OAuth2 redirect URL added to that application
|
|
287
|
-
- The proper libraries, DLLs, and header files in the right places for your game
|
|
288
|
-
- A working SDK, via the small code snippets above
|
|
289
|
-
|
|
290
|
-
If you can check all those boxes, you are doing great! You're well-equipped to venture forth into the rest of the SDK and make full use of it's myriad of functionality. So, onwards, to game development!
|
|
291
|
-
|
|
292
|
-
If you ever need help during the process, you can always reach out to us at our [Dev Support](https://dis.gd/devsupport). If you have feedback on things you'd like to see added to the SDK, drop us at a line at our [Dev Feedback](https://dis.gd/devfeedback).
|
|
293
|
-
|
|
294
|
-
## Where...do I go...
|
|
295
|
-
|
|
296
|
-
Oh, yeah. Pseudo Table of Contents:
|
|
297
|
-
|
|
298
|
-
- [The Core - Start Here!](#DOCS_GAME_SDK_DISCORD/)
|
|
299
|
-
- [Activities, a.k.a. Rich Presence](#DOCS_GAME_SDK_ACTIVITIES/)
|
|
300
|
-
- [Relationships](#DOCS_GAME_SDK_RELATIONSHIPS/)
|
|
301
|
-
- [Users](#DOCS_GAME_SDK_USERS/)
|
|
302
|
-
- [Images](#DOCS_GAME_SDK_IMAGES/)
|
|
303
|
-
- [Lobbies](#DOCS_GAME_SDK_LOBBIES/)
|
|
304
|
-
- [Networking](#DOCS_GAME_SDK_NETWORKING/)
|
|
305
|
-
- [Storage](#DOCS_GAME_SDK_STORAGE/)
|
|
306
|
-
- [Applications](#DOCS_GAME_SDK_APPLICATIONS/)
|
|
307
|
-
- [Overlay](#DOCS_GAME_SDK_OVERLAY/)
|
|
308
|
-
- [Store](#DOCS_GAME_SDK_STORE/)
|
|
309
|
-
- [Discord Voice](#DOCS_GAME_SDK_DISCORD_VOICE/)
|
|
310
|
-
- [Achievements](#DOCS_GAME_SDK_ACHIEVEMENTS/)
|