You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/activities/building-an-activity.mdx
+14-21Lines changed: 14 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ It assumes an understanding of [JavaScript](https://developer.mozilla.org/en-US/
16
16
17
17
<Collapsibletitle="What we'll be building"icon="view">
18
18
19
-

19
+

20
20
21
21
</Collapsible>
22
22
@@ -88,7 +88,7 @@ npm install
88
88
npm run dev
89
89
```
90
90
91
-
If you visit http://localhost:3000/ you should see a vanilla JS frontend template running with [Vite](https://vitejs.dev/).
91
+
If you visit http://localhost:5173/ you should see a vanilla JS frontend template running with [Vite](https://vitejs.dev/).
92
92
93
93
While it's not much at the moment, in the following steps we'll connect it to the backend services, make it runnable in Discord, and power it up by populating it with data we pull from Discord APIs.
94
94
@@ -107,7 +107,7 @@ By the end of Step 1, you should have:
107
107
108
108
With our project set up, let's create our app and configure the Activity. Create a new app in the developer portal if you don't have one already:
Enter a name for your app, select a development team, then press **Create**.
113
113
@@ -145,7 +145,7 @@ You can learn more about the OAuth flow and redirect URIs in the [OAuth2 documen
145
145
146
146
Click on **OAuth2** on the sidebar in your app's settings. Under **Redirects**, enter `https://127.0.0.1` as a placeholder value then click **Save Changes**.
147
147
148
-

148
+

149
149
150
150
### Fetch Your OAuth2 Credentials
151
151
@@ -278,7 +278,7 @@ Your app should start and you should see output similar to the following:
278
278
```
279
279
VITE v5.0.12 ready in100 ms
280
280
281
-
➜ Local: http://localhost:3000/
281
+
➜ Local: http://localhost:5173/
282
282
➜ Network: use --host to expose
283
283
➜ press h + enter to show help
284
284
```
@@ -289,10 +289,10 @@ We'll use the Local URL as our publicly-accessible URL in the next step.
289
289
290
290
Next, we'll need to set up the public endpoint that serves the Activity's frontend. To do that, we'll create a tunnel with a reverse proxy. While we'll be using [`cloudflared`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) in this guide, you can use [ngrok](https://ngrok.com/docs) or another reverse proxy solution if you prefer.
291
291
292
-
While your app is still running, open another terminal window and start a network tunnel that listens to the port from the last step (in this case, port `3000`):
292
+
While your app is still running, open another terminal window and start a network tunnel that listens to the port from the last step (in this case, port `5173`):
293
293
294
294
```
295
-
cloudflared tunnel --url http://localhost:3000
295
+
cloudflared tunnel --url http://localhost:5173
296
296
```
297
297
298
298
When you run `cloudflared`, the tunnel will generate a public URL and you'll see output similar to the following:
@@ -310,7 +310,7 @@ Because Activities are in a sandbox enviornment and go through the Discord proxy
310
310
311
311
Back in your app's settings, click on the **URL Mappings** page under **Activities** on the left-hand sidebar. Enter the URL you generated from `cloudflared` in the previous step.
312
312
313
-

313
+

@@ -324,7 +324,7 @@ Next, we'll need to enable Activities for your app. On the left hand sidebar und
324
324
325
325
Find the first checkbox, labeled `Enable Activities`. Turn it on 🎉
326
326
327
-

327
+

328
328
329
329
#### Default Entry Point Command
330
330
@@ -341,7 +341,7 @@ Navigate to your Discord test server and, in any voice and or text channel, open
341
341
342
342
Clicking on your app will launch your locally running app from inside Discord!
343
343
344
-

344
+

345
345
346
346
:::info
347
347
**Customizing your Activity**
@@ -457,10 +457,6 @@ We can now run our server and client-side apps in separate terminal windows. You
457
457
458
458
Before we call your backend activity server, we need to be aware of the Discord proxy and understand how to avoid any Content Security Policy (CSP) issues.
459
459
460
-
:::info
461
-
For this tutorial, we are going to prefix the API call to `/api/token/` with `/.proxy`, but you can also use the SDK's `patchUrlMappings()` method to automatically prefix calls to your external resources for the proxy.
462
-
:::
463
-
464
460
Learn more about this topic in the guides for [Constructing a Full URL](/docs/activities/development-guides/networking#construct-a-full-url) and [Using External Resources](/docs/activities/development-guides/networking#using-external-resources).
465
461
466
462
### Calling your backend server from your client
@@ -513,10 +509,7 @@ async function setupDiscordSdk() {
513
509
});
514
510
515
511
// Retrieve an access_token from your activity's server
516
-
// Note: We need to prefix our backend `/api/token` route with `/.proxy` to stay compliant with the CSP.
517
-
// Read more about constructing a full URL and using external resources at
- This allows for easier drop-in drop-out behavior for the large portion of mobile users on Discord.
@@ -80,7 +80,7 @@ Make your app fast, easy to join, and maximize fun to launch a crowd favorite.
80
80
- Activities are frictionless to join and easy to discover, so you can expect that users will join mid-experience. Give those users something to do, even if it's just letting them spectate until they can join without being disruptive. In the same vein, users can leave without notice or become afk (away from keyboard). Handle these cases gracefully.
81
81
- Create a case for users who have joined a call but have not yet started playing or engaging. Allow these users to "spectate" other users who are playing. This can also be helpful for Activities that have an ideal number in mind for play.
82
82
83
-

83
+

84
84
85
85
### Make your app as available as possible
86
86
@@ -105,7 +105,7 @@ Discord is a social platform where users talk to each other. Sharing and invites
105
105
- Share photos or GIFs that capture moments of fun and memorable, or something to brag about. Don't make things shareable just to feature the activity.
106
106
- Sharing a high score alone may not be very engaging, but sharing a really good move made in a game, or a collaborative drawing that creates a memory is a conversation starter and may make others want to join in on the fun.
107
107
108
-

108
+

109
109
110
110
#### Activities in Text Channels
111
111
- The Activity user interface, copy and user flows should not rely on people in voice to explain, organize, clarify, or instruct about how the activity works.
@@ -141,8 +141,7 @@ Monetization in Activities will be available soon. Keep the following considerat
141
141
142
142
### Activities close when the last participant in the Activity leaves it
143
143
- The next time the Activity is launched, even if it’s in the same DM or Voice Channel, it will be a different instance and could have different participants.
144
-
- Note: This behavior will change in 2024, when we release persistent instances.
145
-
144
+
146
145
### If a game is launched, what % of the time do users reach different phases of the game?
147
146
- This includes launch → start, as there can be a large dropoff between these two (especially if you don’t support solo play or small group sizes).
148
147
- This also includes various check points in the game, including what % of sessions that start a game reach the end of that game!
@@ -151,10 +150,10 @@ Monetization in Activities will be available soon. Keep the following considerat
151
150
- If drop-off is really high at a certain point, see if you can figure out why or change flows.
152
151
153
152
### How many games are played in a session?
154
-
- More games per session isn’t inherently better (you may have an Activity that is meant to be one long game), but is a good baseline to understand.
153
+
- More games per session isn’t inherently better (you may have an Activity that is meant to be one long game), but is a good baseline to understand.
155
154
- If you expect to see a lot of repeat plays per session and don’t, it can be worth digging in to understand more.
156
155
157
-
### How does the group size impact various key metrics?
156
+
### How does the group size impact various key metrics?
158
157
- For example, are larger sessions more or less likely to reach the end of a game? To replay? Etc.
159
158
- This can help you catch if your Activity has unexpected weak points in different group sizes — maybe the game drags on if there are too many people or isn’t compelling enough if there’s only two.
160
159
- Not every Activity needs to be built for robust group sizes, but if you have the option to play with X # of players, it’s good practice to make sure that experience is enjoyable for all involved!
Users will see an embed with your information displayed. Clicking "Play" opens the activity and passes through the `custom_id` you've set. A `referrer_id` will be present for links shared on Discord.
It's also possible to configure an application with a default orientation lock state via the Developer Portal. Using this method, the Discord app will apply the orientation lock when launching the application before the SDK has been initialized. This can create a smoother application launch flow where the application starts in the correct orientation rather than switching to the correct orientation after some delay after the application requests an orientation lock via the SDK. The Developer Portal supports setting a different default orientation lock states for phones versus tablets.
In the Discord Developer Portal, update the Application URL mapping for `/` url to `funky-jogging-bunny.trycloudflare.com` to match your network tunnel address and save your changes.
43
43
44
-

44
+

45
45
46
46
:::warn
47
47
If you do not own the URL that you are using to host the application (i.e. ngrok's free tier), someone else could claim that domain and host a malicious site in its place. Please be aware of these risks, and if you have to use a domain you do not own, be sure to reset your URL mapping when you are done using the tunnel.
@@ -59,7 +59,7 @@ The flow for setting up your production application is very similar:
59
59
4. Follow the instructions for [Launching your Application from the Discord Client](/docs/activities/development-guides/local-development#launch-your-application-from-the-discord-client). Application URL Override should not be enabled.
60
60
61
61
This application now uses the same configuration it will use once it is fully published ✨.
@@ -96,7 +96,7 @@ Because your application is "sandboxed", it will be unable to make network reque
96
96
97
97
To add or modify your application's URL mappings, click on `Activities -> URL Mappings` and set the prefix and target values for each mapping as needed.
98
98
99
-

99
+

100
100
101
101
#### Prefix/Target formatting rules
102
102
@@ -108,10 +108,10 @@ To add or modify your application's URL mappings, click on `Activities -> URL Ma
108
108
- Targets must point to a directory; setting a target to a file (e.g. `example.com/index.html`) is unsupported and may lead to unexpected behavior.
109
109
- Because of how URL globbing works, if you have multiple prefix urls with the same initial path, you must place the shortest of the prefix paths last in order for each url mapping to be reachable. For example, if you have `/foo` and `/foo/bar`, you must place the url `/foo/bar` before `/foo` or else the mapping for `/foo/bar` will never be reached.
Copy file name to clipboardExpand all lines: docs/activities/development-guides/mobile.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ By default, your Activity will be launchable on web/desktop. To enable or disabl
15
15
- Select `Activities` -> `Settings` in the left-side of the developer portal, or visit `https://discord.com/developers/<your app id>/embedded/settings`
16
16
- From check the appropriate checkboxes in the developer portal, and save your changes
0 commit comments