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,237 +0,0 @@
|
|
|
1
|
-
# Applications
|
|
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
|
-
Many games run their own backend servers for things like user authentication. If one of those many games is yours, then we've got something for you! This manager gives you access to a bearer token for the currently connected Discord user, which you can send off to your server to do user authentication.
|
|
10
|
-
|
|
11
|
-
This token is also useful for retrieving information about the connected user's account. Check out our [OAuth2 documentation](https://discord.com/developers/docs/topics/oauth2) for more information.
|
|
12
|
-
|
|
13
|
-
These bearer tokens are good for seven days, after which they will expire. When a user reconnects to your game, and is online and connected to the internet, they'll receive a new token that you can grab.
|
|
14
|
-
|
|
15
|
-
This manager also includes a couple useful helper functions, like getting the locale in which the user has chosen to use their Discord client, and knowing which game branch the game is running on. More about branches in the Dispatch CLI tool section of the documentation.
|
|
16
|
-
|
|
17
|
-
## Data Models
|
|
18
|
-
|
|
19
|
-
###### OAuth2Token Struct
|
|
20
|
-
|
|
21
|
-
| name | type | description |
|
|
22
|
-
| ----------- | ------ | ----------------------------------------------------------------------------------------------- |
|
|
23
|
-
| AccessToken | string | a bearer token for the current user |
|
|
24
|
-
| Scopes | string | a list of oauth2 scopes as a single string, delineated by spaces like `"identify rpc gdm.join"` |
|
|
25
|
-
| Expires | Int64 | the timestamp at which the token expires |
|
|
26
|
-
|
|
27
|
-
###### SignedAppTicket Struct
|
|
28
|
-
|
|
29
|
-
| name | type | description |
|
|
30
|
-
| -------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------- |
|
|
31
|
-
| application_id | Int64 | the application id for the ticket |
|
|
32
|
-
| user | [User](#DOCS_GAME_SDK_USERS/data-models-user-struct) | the user for the ticket |
|
|
33
|
-
| entitlements | list of partial [Entitlements](#DOCS_GAME_SDK_STORE/data-models-entitlement-struct) structs that contain just the SKU id | the list of the user's entitlements for this application |
|
|
34
|
-
| timestamp | string | the ISO 8601 timestamp for the ticket |
|
|
35
|
-
|
|
36
|
-
## GetCurrentLocale
|
|
37
|
-
|
|
38
|
-
> info
|
|
39
|
-
> Value from environment variable `DISCORD_CURRENT_LOCALE`
|
|
40
|
-
|
|
41
|
-
Gets the locale the current user has Discord set to.
|
|
42
|
-
|
|
43
|
-
Returns a `string`.
|
|
44
|
-
|
|
45
|
-
###### Parameters
|
|
46
|
-
|
|
47
|
-
None
|
|
48
|
-
|
|
49
|
-
###### Example
|
|
50
|
-
|
|
51
|
-
```cs
|
|
52
|
-
var locale = applicationManager.GetCurrentLocale();
|
|
53
|
-
Console.WriteLine("This user's language is {0}", locale);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## GetCurrentBranch
|
|
57
|
-
|
|
58
|
-
> info
|
|
59
|
-
> Value from environment variable `DISCORD_CURRENT_BRANCH`
|
|
60
|
-
|
|
61
|
-
Get the name of pushed branch on which the game is running. These are branches that you created and pushed using Dispatch.
|
|
62
|
-
|
|
63
|
-
###### Parameters
|
|
64
|
-
|
|
65
|
-
None
|
|
66
|
-
|
|
67
|
-
###### Example
|
|
68
|
-
|
|
69
|
-
```cs
|
|
70
|
-
var branch = applicationManager.GetCurrentBranch();
|
|
71
|
-
if (branch != MyBranches.Stable)
|
|
72
|
-
{
|
|
73
|
-
Console.WriteLine("You are on a beta branch; expect bugs!");
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## GetOAuth2Token
|
|
78
|
-
|
|
79
|
-
> info
|
|
80
|
-
> value from environment variable `DISCORD_ACCESS_TOKEN`
|
|
81
|
-
|
|
82
|
-
> warn
|
|
83
|
-
> Ensure that you have `http://127.0.0.1` set as a valid redirect URI for your application in the Developer Portal, or this method will always return an error.
|
|
84
|
-
|
|
85
|
-
Retrieve an oauth2 bearer token for the current user. If your game was launched from Discord and you call this function, you will automatically receive the token. If the game was _not_ launched from Discord and this method is called, Discord will focus itself and prompt the user for authorization.
|
|
86
|
-
|
|
87
|
-
Returns a `Discord.Result` and a `ref Discord.OAuth2Token` via callback.
|
|
88
|
-
|
|
89
|
-
###### Parameters
|
|
90
|
-
|
|
91
|
-
None
|
|
92
|
-
|
|
93
|
-
###### Example
|
|
94
|
-
|
|
95
|
-
```cs
|
|
96
|
-
applicationManager.GetOAuth2Token((Discord.Result result, ref Discord.OAuth2Token token) =>
|
|
97
|
-
{
|
|
98
|
-
if (result == Discord.Result.Ok)
|
|
99
|
-
{
|
|
100
|
-
Console.WriteLine("Token for the user: {0}. Expires in {1}", token.AccessToken, token.Expires);
|
|
101
|
-
// You may now use this token against Discord's HTTP API
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## ValidateOrExit
|
|
107
|
-
|
|
108
|
-
Checks if the current user has the entitlement to run this game.
|
|
109
|
-
|
|
110
|
-
Returns a `Discord.Result` via callback.
|
|
111
|
-
|
|
112
|
-
###### Parameters
|
|
113
|
-
|
|
114
|
-
None
|
|
115
|
-
|
|
116
|
-
###### Example
|
|
117
|
-
|
|
118
|
-
```cs
|
|
119
|
-
applicationManager.ValidateOrExit((result) =>
|
|
120
|
-
{
|
|
121
|
-
if (result == Discord.Result.Ok)
|
|
122
|
-
{
|
|
123
|
-
// Game keeps running
|
|
124
|
-
}
|
|
125
|
-
else
|
|
126
|
-
{
|
|
127
|
-
Console.WriteLine("Oops! Something went wrong, closing game...");
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## GetTicket
|
|
133
|
-
|
|
134
|
-
###### Current Version
|
|
135
|
-
|
|
136
|
-
| version | status |
|
|
137
|
-
| ------- | ------- |
|
|
138
|
-
| 2 | current |
|
|
139
|
-
|
|
140
|
-
Get the signed app ticket for the current user. The structure of the ticket is: `version.signature.base64encodedjson`, so you should split the string by the `.` character. Ensure that the `version` matches the current version. The `signature` is used to verify the ticket using the libsodium library of your choice, and the `base64encodedjson` is what you can transform after verification. It contains:
|
|
141
|
-
|
|
142
|
-
- the application id tied to the ticket
|
|
143
|
-
- the user's user id
|
|
144
|
-
- a timestamp for the ticket
|
|
145
|
-
- the list of the user's [entitlements](#DOCS_GAME_SDK_STORE/data-models-entitlement-struct) for the application id
|
|
146
|
-
|
|
147
|
-
These values can be accessed by transforming the string into a [SignedAppTicket](#DOCS_GAME_SDK_APPLICATIONS/data-models-signedappticket-struct) with your application's private key. The ticket is signed using [libsodium](https://github.com/jedisct1/libsodium) which should be available for any programming language. Here's a [list of available libraries](https://download.libsodium.org/doc/bindings_for_other_languages).
|
|
148
|
-
|
|
149
|
-
Note that both the public key you receive from Discord and the signature within the app ticket from the SDK are both in hex, and will need to be converted to `byte[]` before use with libsodium.
|
|
150
|
-
|
|
151
|
-
Returns a `Discord.Result` and `ref string` via callback.
|
|
152
|
-
|
|
153
|
-
###### Parameters
|
|
154
|
-
|
|
155
|
-
None
|
|
156
|
-
|
|
157
|
-
###### Example
|
|
158
|
-
|
|
159
|
-
```cs
|
|
160
|
-
// Handle serialization however works best for you
|
|
161
|
-
// This is just an easy example
|
|
162
|
-
[Serializable]
|
|
163
|
-
public class SignedAppTicket
|
|
164
|
-
{
|
|
165
|
-
public long application_id;
|
|
166
|
-
public Discord.User user;
|
|
167
|
-
public List<Discord.Entitlement> entitlements;
|
|
168
|
-
public string timestamp;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public void DoTheThing()
|
|
172
|
-
{
|
|
173
|
-
// This example is using the libsodium-net library
|
|
174
|
-
// https://github.com/adamcaudill/libsodium-net
|
|
175
|
-
var appManager = discord.GetApplicationManager();
|
|
176
|
-
var MY_PUBLIC_KEY = "460cab5f2237b71e3c2c06bzze217f4f68d55db16dae672bdfb6618235589999";
|
|
177
|
-
var MY_SKU_ID = "492432195219099999";
|
|
178
|
-
|
|
179
|
-
// Get the ticket
|
|
180
|
-
appManager.GetTicket((Discord.Result res, ref string ticket) =>
|
|
181
|
-
{
|
|
182
|
-
// Split the ticket into its parts
|
|
183
|
-
var parts = ticket.Split('.');
|
|
184
|
-
|
|
185
|
-
// Ensure the version matches
|
|
186
|
-
if(parts[0] == "2")
|
|
187
|
-
{
|
|
188
|
-
// Verify the signature
|
|
189
|
-
// Your public key will be given to you by Discord
|
|
190
|
-
if (Sodium.PublicKeyAuth.VerifyDetached(HexToByte(parts[1]), System.Text.Encoding.UTF8.GetBytes(parts[2]), HexToByte(MY_PUBLIC_KEY)))
|
|
191
|
-
{
|
|
192
|
-
// If valid, decode the string
|
|
193
|
-
var byteData = Convert.FromBase64String(parts[2]);
|
|
194
|
-
var json = System.Text.Encoding.UTF8.GetString(byteData);
|
|
195
|
-
|
|
196
|
-
// Deserialize it into the ticket object
|
|
197
|
-
var myTicket = Newtonsoft.Json.JsonConvert.DeserializeObject<SignedAppTicket>(json);
|
|
198
|
-
|
|
199
|
-
// Check for entitlement to the SKU!
|
|
200
|
-
if (myTicket.entitlements.Any(x => x.SkuId == MY_SKU_ID))
|
|
201
|
-
{
|
|
202
|
-
Console.WriteLine("User has entitlement to your game");
|
|
203
|
-
}
|
|
204
|
-
else
|
|
205
|
-
{
|
|
206
|
-
Console.WriteLine("Not entitled");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
public byte[] HexToByte(string hex)
|
|
214
|
-
{
|
|
215
|
-
byte[] data = new byte[hex.Length / 2];
|
|
216
|
-
for (int i = 0; i < hex.Length; i +=2)
|
|
217
|
-
{
|
|
218
|
-
data[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
|
|
219
|
-
}
|
|
220
|
-
return data;
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## Example: Get OAuth2 Token
|
|
225
|
-
|
|
226
|
-
```cs
|
|
227
|
-
var discord = new Discord.Discord(clientId, Discord.CreateFlags.Default);
|
|
228
|
-
var appManager = discord.GetApplicationManager();
|
|
229
|
-
|
|
230
|
-
// Retrieve the token
|
|
231
|
-
appManager.GetOAuth2Token((Discord.Result result, ref Discord.OAuth2Token token) =>
|
|
232
|
-
{
|
|
233
|
-
Console.WriteLine(token.AccessToken);
|
|
234
|
-
|
|
235
|
-
// Now send that token off to your server to do your own validation!
|
|
236
|
-
})
|
|
237
|
-
```
|
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
# Discord
|
|
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
|
-
Making a game? Need a whole bunch of fancy APIs to help make it great and your players' lives a breeze? Look no further! The Discord GameSDK is an easy drop-in SDK to help you manage all the hard things that come with making a game. Well, all the hards things about coding it at least. Interpersonal communication skills are on you (have you heard of this cool chat app called Discord?).
|
|
10
|
-
|
|
11
|
-
OK, cool, so how's it work?
|
|
12
|
-
|
|
13
|
-
## General Structure
|
|
14
|
-
|
|
15
|
-
At a high level, the Discord GameSDK has a class, `Discord`. This class is in charge of the creation of a few "manager" sub-classes. They are:
|
|
16
|
-
|
|
17
|
-
- `AchievementManager` - for achievements!
|
|
18
|
-
- `ActivityManager` - for Rich Presence and game invites
|
|
19
|
-
- `ApplicationManager` - for retrieving a user's OAuth2 bearer token, locale, and current game branch
|
|
20
|
-
- `ImageManager` - for getting data about images on Discord, like user avatars or chat images
|
|
21
|
-
- `LobbyManager` - for multiplayer lobbies
|
|
22
|
-
- `NetworkManager` - for all your networking layer needs
|
|
23
|
-
- `OverlayManager` - for interacting with Discord's built-in overlay
|
|
24
|
-
- `RelationshipManager` - for users' social relationships across Discord, including friends list
|
|
25
|
-
- `StorageManager` - for saving game data to the disk and the cloud
|
|
26
|
-
- `StoreManager` - for all things entitlements and SKUs, including IAP functionality
|
|
27
|
-
- `UserManager` - for fetching user data for a given id and the current user
|
|
28
|
-
- `VoiceManager` - to make use of Discord's awesome voice chat
|
|
29
|
-
|
|
30
|
-
Each one of these managers contain a number of methods and events used to interact with Discord in the context of the manager. For example, `RelationshipManager` has a function called `Filter()`, which lets you pare down a user's inter-Discord relationships based on a boolean condition, like being friends!
|
|
31
|
-
|
|
32
|
-
## Functions in the SDK
|
|
33
|
-
|
|
34
|
-
Most functions in the Discord GameSDK, uh, _function_ in a similar way. They take whatever parameters are required for the function to do its job—a user id, the requested size for an image, etc.—and a callback by means of a function pointer. That callback is fired when the function completes its work, letting you handle events without worrying about piping asynchronously-returned data to the right context.
|
|
35
|
-
|
|
36
|
-
Some functions behave with a normal return behavior; e.g. `RelationshipManager.Count()` just returns the number directly. Don't worry, it's outlined in the docs.
|
|
37
|
-
|
|
38
|
-
A quick example with our C# binding:
|
|
39
|
-
|
|
40
|
-
```c#
|
|
41
|
-
var userManager = discord.GetUserManager();
|
|
42
|
-
|
|
43
|
-
// Return via callback
|
|
44
|
-
userManager.GetUser(290926444748734465, (Discord.Result result, ref Discord.User otherUser) =>
|
|
45
|
-
{
|
|
46
|
-
if (result == Discord.Result.Ok)
|
|
47
|
-
{
|
|
48
|
-
Console.WriteLine(otherUser.Username);
|
|
49
|
-
Console.WriteLine(otherUser.Id);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Return normally
|
|
55
|
-
userManager.OnCurrentUserUpdate += () =>
|
|
56
|
-
{
|
|
57
|
-
var currentUser = userManager.GetCurrentUser();
|
|
58
|
-
Console.WriteLine(currentUser.Username);
|
|
59
|
-
Console.WriteLine(currentUser.Discriminator);
|
|
60
|
-
Console.WriteLine(currentUser.Id);
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Environment Variables
|
|
66
|
-
|
|
67
|
-
Discord passes a number of environment variables down to the SDK. These are accessed by various methods in the SDK and can be changed for local testing by changing the value in your local environment.
|
|
68
|
-
|
|
69
|
-
###### SDK Environment Variables
|
|
70
|
-
|
|
71
|
-
| name | method | description |
|
|
72
|
-
|------------------------|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
|
|
73
|
-
| DISCORD_INSTANCE_ID | [Local Testing](#DOCS_GAME_SDK_SDK_STARTER_GUIDE/testing-locally-with-two-clients) | the locally running instance of Discord to connect to; allows you to choose between multiple running clients |
|
|
74
|
-
| DISCORD_ACCESS_TOKEN | [ApplicationManager.GetOAuth2Token()](#DOCS_GAME_SDK_APPLICATIONS/getoauth2token) | the connected user's bearer token |
|
|
75
|
-
| DISCORD_CURRENT_LOCALE | [ApplicationManager.GetCurrentLocale()](#DOCS_GAME_SDK_APPLICATIONS/getcurrentlocale) | the language that Discord is in for the connected user |
|
|
76
|
-
| DISCORD_CURRENT_BRANCH | [ApplicationManager.GetCurrentBranch()](#DOCS_GAME_SDK_APPLICATIONS/getcurrentbranch) | the branch of the running application that the user has launched |
|
|
77
|
-
| DISCORD_STORAGE_PATH | [StorageManager.GetPath()](#DOCS_GAME_SDK_STORAGE/getpath) | the path to which Discord will save files if you're using the StorageManager |
|
|
78
|
-
|
|
79
|
-
## Error Handling
|
|
80
|
-
|
|
81
|
-
Debugging is a pain, so before we get into the meat of the SDK, we want to make sure you're prepared for when things go awry. Within the Discord core is a function called `SetLogHook()`. It takes a `level`, which is minimum level of log message you want to listen to, and a callback function:
|
|
82
|
-
|
|
83
|
-
```cs
|
|
84
|
-
public void LogProblemsFunction(Discord.LogLevel level, string message)
|
|
85
|
-
{
|
|
86
|
-
Console.WriteLine("Discord:{0} - {1}", level, message);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
discord.SetLogHook(Discord.LogLevel.Debug, LogProblemsFunction);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
You should begin your integration by setting up this callback to help you debug. Helpfully, if you put a breakpoint inside the callback function you register here, you'll be able to see the stack trace for errors you run into (as long as they fail synchronously). Take the guess work out of debugging, or hey, ignore any and all logging by setting a callback that does nothing. We're not here to judge.
|
|
93
|
-
|
|
94
|
-
## Data Models
|
|
95
|
-
|
|
96
|
-
###### Result Enum
|
|
97
|
-
|
|
98
|
-
| Code | value | description |
|
|
99
|
-
|------|---------------------------------|-------------------------------------------------------------------------------------------------|
|
|
100
|
-
| 0 | Ok | everything is good |
|
|
101
|
-
| 1 | ServiceUnavailable | Discord isn't working |
|
|
102
|
-
| 2 | InvalidVersion | the SDK version may be outdated |
|
|
103
|
-
| 3 | LockFailed | an internal error on transactional operations |
|
|
104
|
-
| 4 | InternalError | something on our side went wrong |
|
|
105
|
-
| 5 | InvalidPayload | the data you sent didn't match what we expect |
|
|
106
|
-
| 6 | InvalidCommand | that's not a thing you can do |
|
|
107
|
-
| 7 | InvalidPermissions | you aren't authorized to do that |
|
|
108
|
-
| 8 | NotFetched | couldn't fetch what you wanted |
|
|
109
|
-
| 9 | NotFound | what you're looking for doesn't exist |
|
|
110
|
-
| 10 | Conflict | user already has a network connection open on that channel |
|
|
111
|
-
| 11 | InvalidSecret | activity secrets must be unique and not match party id |
|
|
112
|
-
| 12 | InvalidJoinSecret | join request for that user does not exist |
|
|
113
|
-
| 13 | NoEligibleActivity | you accidentally set an `ApplicationId` in your `UpdateActivity()` payload |
|
|
114
|
-
| 14 | InvalidInvite | your game invite is no longer valid |
|
|
115
|
-
| 15 | NotAuthenticated | the internal auth call failed for the user, and you can't do this |
|
|
116
|
-
| 16 | InvalidAccessToken | the user's bearer token is invalid |
|
|
117
|
-
| 17 | ApplicationMismatch | access token belongs to another application |
|
|
118
|
-
| 18 | InvalidDataUrl | something internally went wrong fetching image data |
|
|
119
|
-
| 19 | InvalidBase64 | not valid Base64 data |
|
|
120
|
-
| 20 | NotFiltered | you're trying to access the list before creating a stable list with `Filter()` |
|
|
121
|
-
| 21 | LobbyFull | the lobby is full |
|
|
122
|
-
| 22 | InvalidLobbySecret | the secret you're using to connect is wrong |
|
|
123
|
-
| 23 | InvalidFilename | file name is too long |
|
|
124
|
-
| 24 | InvalidFileSize | file is too large |
|
|
125
|
-
| 25 | InvalidEntitlement | the user does not have the right entitlement for this game |
|
|
126
|
-
| 26 | NotInstalled | Discord is not installed |
|
|
127
|
-
| 27 | NotRunning | Discord is not running |
|
|
128
|
-
| 28 | InsufficientBuffer | insufficient buffer space when trying to write |
|
|
129
|
-
| 29 | PurchaseCancelled | user cancelled the purchase flow |
|
|
130
|
-
| 30 | InvalidGuild | Discord guild does not exist |
|
|
131
|
-
| 31 | InvalidEvent | the event you're trying to subscribe to does not exist |
|
|
132
|
-
| 32 | InvalidChannel | Discord channel does not exist |
|
|
133
|
-
| 33 | InvalidOrigin | the origin header on the socket does not match what you've registered (you should not see this) |
|
|
134
|
-
| 34 | RateLimited | you are calling that method too quickly |
|
|
135
|
-
| 35 | OAuth2Error | the OAuth2 process failed at some point |
|
|
136
|
-
| 36 | SelectChannelTimeout | the user took too long selecting a channel for an invite |
|
|
137
|
-
| 37 | GetGuildTimeout | took too long trying to fetch the guild |
|
|
138
|
-
| 38 | SelectVoiceForceRequired | push to talk is required for this channel |
|
|
139
|
-
| 39 | CaptureShortcutAlreadyListening | that push to talk shortcut is already registered |
|
|
140
|
-
| 40 | UnauthorizedForAchievement | your application cannot update this achievement |
|
|
141
|
-
| 41 | InvalidGiftCode | the gift code is not valid |
|
|
142
|
-
| 42 | PurchaseError | something went wrong during the purchase flow |
|
|
143
|
-
| 43 | TransactionAborted | purchase flow aborted because the SDK is being torn down |
|
|
144
|
-
|
|
145
|
-
###### LogLevel Enum
|
|
146
|
-
|
|
147
|
-
| value | description |
|
|
148
|
-
|---------|--------------------------------|
|
|
149
|
-
| Error | Log only errors |
|
|
150
|
-
| Warning | Log warnings and errors |
|
|
151
|
-
| Info | Log info, warnings, and errors |
|
|
152
|
-
| Debug | Log _all_ the things! |
|
|
153
|
-
|
|
154
|
-
###### CreateFlags Enum
|
|
155
|
-
|
|
156
|
-
| value | description |
|
|
157
|
-
|------------------|---------------------------------------------------------------------|
|
|
158
|
-
| Default | Requires Discord to be running to play the game |
|
|
159
|
-
| NoRequireDiscord | Does not require Discord to be running, use this on other platforms |
|
|
160
|
-
|
|
161
|
-
## Create
|
|
162
|
-
|
|
163
|
-
Creates an instance of Discord to initialize the SDK. This is the overlord of all things Discord. We like to call her Nelly.
|
|
164
|
-
|
|
165
|
-
Returns a new `Discord`.
|
|
166
|
-
|
|
167
|
-
###### Parameters
|
|
168
|
-
|
|
169
|
-
| name | type | description |
|
|
170
|
-
|----------|-------------|-----------------------------------------------------|
|
|
171
|
-
| clientId | Int64 | your application's client id |
|
|
172
|
-
| flags | CreateFlags | the creation parameters for the SDK, outlined above |
|
|
173
|
-
|
|
174
|
-
###### Example
|
|
175
|
-
|
|
176
|
-
```
|
|
177
|
-
// c++ land
|
|
178
|
-
discord::Core* core{};
|
|
179
|
-
discord::Core::Create(53908232506183680, DiscordCreateFlags_Default, &core);
|
|
180
|
-
|
|
181
|
-
// c# land
|
|
182
|
-
var discord = new Discord(53908232506183680, (UInt64)Discord.CreateFlags.Default);
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## Destroy
|
|
186
|
-
|
|
187
|
-
Destroys the instance. Wave goodbye, Nelly! You monster. In C# land, this is `Dispose()`.
|
|
188
|
-
|
|
189
|
-
> info
|
|
190
|
-
> The C++ binding does not include a `destroy()` method, as the destructor for the Core does the work for you.
|
|
191
|
-
|
|
192
|
-
Returns `void`.
|
|
193
|
-
|
|
194
|
-
###### Parameters
|
|
195
|
-
|
|
196
|
-
None
|
|
197
|
-
|
|
198
|
-
###### Example
|
|
199
|
-
|
|
200
|
-
```cs
|
|
201
|
-
discord.Dispose();
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## SetLogHook
|
|
205
|
-
|
|
206
|
-
Registers a logging callback function with the minimum level of message to receive. The callback function should have a signature of:
|
|
207
|
-
|
|
208
|
-
```
|
|
209
|
-
MyCallbackFunction(LogLevel level, string message);
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
Returns `void`.
|
|
213
|
-
|
|
214
|
-
###### Parameters
|
|
215
|
-
|
|
216
|
-
| name | type | description |
|
|
217
|
-
|----------|----------|---------------------------------------------|
|
|
218
|
-
| level | LogLevel | the minimum level of event to log |
|
|
219
|
-
| callback | function | the callback function to catch the messages |
|
|
220
|
-
|
|
221
|
-
###### Example
|
|
222
|
-
|
|
223
|
-
```cs
|
|
224
|
-
public void LogProblemsFunction(Discord.LogLevel level, string message)
|
|
225
|
-
{
|
|
226
|
-
Console.WriteLine("Discord:{0} - {1}", level, message);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
discord.SetLogHook(Discord.LogLevel.Debug, LogProblemFunctions);
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## RunCallbacks
|
|
233
|
-
|
|
234
|
-
Runs all pending SDK callbacks. Put this in your game's main event loop, like `Update()` in Unity. That way, the first thing your game does is check for any new info from Discord.
|
|
235
|
-
|
|
236
|
-
This function also serves as a way to know that the local Discord client is still connected. If the user closes Discord while playing your game, `RunCallbacks()` will return/throw `Discord.Result.NotRunning`.
|
|
237
|
-
|
|
238
|
-
In C and C++, this function returns `Discord.Result`. In C#, it returns `void` and will throw `Discord.Result` error if something went wrong.
|
|
239
|
-
|
|
240
|
-
###### Parameters
|
|
241
|
-
|
|
242
|
-
None
|
|
243
|
-
|
|
244
|
-
###### Example
|
|
245
|
-
|
|
246
|
-
```cs
|
|
247
|
-
void Update()
|
|
248
|
-
{
|
|
249
|
-
discord.RunCallbacks();
|
|
250
|
-
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
## GetActivityManager
|
|
254
|
-
|
|
255
|
-
Fetches an instance of the manager for interfacing with activities in the SDK.
|
|
256
|
-
|
|
257
|
-
Returns an `ActivityManager`.
|
|
258
|
-
|
|
259
|
-
###### Parameters
|
|
260
|
-
|
|
261
|
-
None
|
|
262
|
-
|
|
263
|
-
###### Example
|
|
264
|
-
|
|
265
|
-
```cs
|
|
266
|
-
var activityManager = discord.GetActivityManager();
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
## GetRelationshipManager
|
|
270
|
-
|
|
271
|
-
Fetches an instance of the manager for interfacing with relationships in the SDK.
|
|
272
|
-
|
|
273
|
-
Returns a `RelationshipManager`.
|
|
274
|
-
|
|
275
|
-
###### Parameters
|
|
276
|
-
|
|
277
|
-
None
|
|
278
|
-
|
|
279
|
-
###### Example
|
|
280
|
-
|
|
281
|
-
```cs
|
|
282
|
-
var relationshipManager = discord.GetRelationshipManager();
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
## GetImageManager
|
|
286
|
-
|
|
287
|
-
Fetches an instance of the manager for interfacing with images in the SDK.
|
|
288
|
-
|
|
289
|
-
Returns an `ImageManager`.
|
|
290
|
-
|
|
291
|
-
###### Parameters
|
|
292
|
-
|
|
293
|
-
None
|
|
294
|
-
|
|
295
|
-
###### Example
|
|
296
|
-
|
|
297
|
-
```cs
|
|
298
|
-
var imageManager = discord.GetImageManager();
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
## GetUserManager
|
|
302
|
-
|
|
303
|
-
Fetches an instance of the manager for interfacing with users in the SDK.
|
|
304
|
-
|
|
305
|
-
Returns an `UserManager`.
|
|
306
|
-
|
|
307
|
-
###### Parameters
|
|
308
|
-
|
|
309
|
-
None
|
|
310
|
-
|
|
311
|
-
###### Example
|
|
312
|
-
|
|
313
|
-
```cs
|
|
314
|
-
var userManager = discord.GetUserManager();
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
## GetLobbyManager
|
|
318
|
-
|
|
319
|
-
Fetches an instance of the manager for interfacing with lobbies in the SDK.
|
|
320
|
-
|
|
321
|
-
Returns a `LobbyManager`.
|
|
322
|
-
|
|
323
|
-
###### Parameters
|
|
324
|
-
|
|
325
|
-
None
|
|
326
|
-
|
|
327
|
-
###### Example
|
|
328
|
-
|
|
329
|
-
```cs
|
|
330
|
-
var lobbyManager = discord.GetLobbyManager();
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
## GetNetworkManager
|
|
334
|
-
|
|
335
|
-
Fetches an instance of the manager for interfacing with networking in the SDK.
|
|
336
|
-
|
|
337
|
-
Returns an `NetworkManager`.
|
|
338
|
-
|
|
339
|
-
###### Parameters
|
|
340
|
-
|
|
341
|
-
None
|
|
342
|
-
|
|
343
|
-
###### Example
|
|
344
|
-
|
|
345
|
-
```cs
|
|
346
|
-
var networkManager = discord.GetNetworkManager();
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
## GetOverlayManager
|
|
350
|
-
|
|
351
|
-
Fetches an instance of the manager for interfacing with the overlay in the SDK.
|
|
352
|
-
|
|
353
|
-
Returns an `OverlayManager`.
|
|
354
|
-
|
|
355
|
-
###### Parameters
|
|
356
|
-
|
|
357
|
-
None
|
|
358
|
-
|
|
359
|
-
###### Example
|
|
360
|
-
|
|
361
|
-
```cs
|
|
362
|
-
var overlayManager = discord.GetOverlayManager();
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
## GetApplicationManager
|
|
366
|
-
|
|
367
|
-
Fetches an instance of the manager for interfacing with applications in the SDK.
|
|
368
|
-
|
|
369
|
-
Returns an `ApplicationManager`.
|
|
370
|
-
|
|
371
|
-
###### Parameters
|
|
372
|
-
|
|
373
|
-
None
|
|
374
|
-
|
|
375
|
-
###### Example
|
|
376
|
-
|
|
377
|
-
```cs
|
|
378
|
-
var applicationManager = discord.GetApplicationManager();
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
## GetStorageManager
|
|
382
|
-
|
|
383
|
-
Fetches an instance of the manager for interfacing with storage in the SDK.
|
|
384
|
-
|
|
385
|
-
Returns a `StorageManager`.
|
|
386
|
-
|
|
387
|
-
###### Parameters
|
|
388
|
-
|
|
389
|
-
None
|
|
390
|
-
|
|
391
|
-
###### Example
|
|
392
|
-
|
|
393
|
-
```cs
|
|
394
|
-
var storageManager = discord.GetStorageManager();
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
## GetStoreManager
|
|
398
|
-
|
|
399
|
-
Fetches an instance of the manager for interfacing with SKUs and Entitlements in the SDK.
|
|
400
|
-
|
|
401
|
-
Returns a `StoreManager`.
|
|
402
|
-
|
|
403
|
-
###### Parameters
|
|
404
|
-
|
|
405
|
-
None
|
|
406
|
-
|
|
407
|
-
###### Example
|
|
408
|
-
|
|
409
|
-
```cs
|
|
410
|
-
var storeManager = discord.GetStoreManager();
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
## GetVoiceManager
|
|
414
|
-
|
|
415
|
-
Fetches an instance of the manager for interfacing with voice chat in the SDK.
|
|
416
|
-
|
|
417
|
-
Returns a `VoiceManager`.
|
|
418
|
-
|
|
419
|
-
###### Parameters
|
|
420
|
-
|
|
421
|
-
None
|
|
422
|
-
|
|
423
|
-
###### Example
|
|
424
|
-
|
|
425
|
-
```cs
|
|
426
|
-
var voiceManager = discord.GetVoiceManager();
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## GetAchievementManager
|
|
430
|
-
|
|
431
|
-
Fetches an instance of the manager for interfacing with achievements in the SDK.
|
|
432
|
-
|
|
433
|
-
Returns an `AchievementManager`.
|
|
434
|
-
|
|
435
|
-
###### Parameters
|
|
436
|
-
|
|
437
|
-
None
|
|
438
|
-
|
|
439
|
-
###### Example
|
|
440
|
-
|
|
441
|
-
```cs
|
|
442
|
-
var achievementManager = discord.GetAchievementManager();
|
|
443
|
-
```
|