|
| 1 | +# Discord Activities |
| 2 | + |
| 3 | +Integrate your Rivet game with [Discord Activities](https://discord.com/developers/docs/activities/overview). |
| 4 | + |
| 5 | +<Steps> |
| 6 | +<Step title="Set up Discord SDK"> |
| 7 | +Set up the Discord SDK ([docs](https://discord.com/developers/docs/activities/building-an-activity#step-3-installing-the-embedded-app-sdk)): |
| 8 | + |
| 9 | +```js |
| 10 | +// Import the SDK |
| 11 | +import { DiscordSDK } from "@discord/embedded-app-sdk"; |
| 12 | + |
| 13 | +// Instantiate the SDK |
| 14 | +const discordSdk = new DiscordSDK(process.env.DISCORD_CLIENT_ID); |
| 15 | + |
| 16 | +setupDiscordSdk().then(() => { |
| 17 | + console.log("Discord SDK is ready"); |
| 18 | +}); |
| 19 | + |
| 20 | +async function setupDiscordSdk() { |
| 21 | + await discordSdk.ready(); |
| 22 | +} |
| 23 | +``` |
| 24 | +</Step> |
| 25 | + |
| 26 | +<Step title="Update lobbies code"> |
| 27 | +Update your Rivet matchmaking code to include tags: |
| 28 | +```js |
| 29 | +const res = await backend.lobbies.findOrCreate({ |
| 30 | + tags: { |
| 31 | + // Discord SDK set up in previous step |
| 32 | + instanceId: discordSdk.instanceId, |
| 33 | + }, |
| 34 | + // ... |
| 35 | +}); |
| 36 | +``` |
| 37 | +</Step> |
| 38 | + |
| 39 | +<Step title="Set up route mapping"> |
| 40 | +After following the [activity tutorial](https://discord.com/developers/docs/activities/building-an-activity), access the [URL mapping](https://discord.com/developers/docs/activities/development-guides#url-mapping) for your Discord app and configure it like so: |
| 41 | + |
| 42 | +| Prefix | Target | |
| 43 | +|--------|--------| |
| 44 | +| /gstatic | fonts.gstatic.com/ | |
| 45 | +| /ws | lobby.rivet.run/ | |
| 46 | +| /api | api.rivet.gg/ | |
| 47 | +| / | asteroids-xxx.rivet.game/ | |
| 48 | + |
| 49 | +<Note> |
| 50 | + The URL used for the "Root Mapping" will be printed in the console when you deploy to Rivet via `rivet deploy`. |
| 51 | +</Note> |
| 52 | +</Step> |
| 53 | + |
| 54 | +<Step title="Run activity"> |
| 55 | +Run activity (read docs [here](https://discord.com/developers/docs/activities/building-an-activity#step-4-running-your-app-locally-in-discord)) |
| 56 | +</Step> |
| 57 | +</Steps> |
| 58 | + |
| 59 | +## Example repo |
| 60 | + |
| 61 | +A fully integrated example can be found [here](https://github.com/rivet-gg/discord-embedded-app-sdk/tree/main/examples/asteroids-rivet). (This is using a slightly dated API, but is lagely identical.) |
0 commit comments