This repo contains an example of a fully multiplayer game running as a Discord activity via Rivet's gaming infrastructure that lets you host your game in just two commands.
- ViteJS
- Express
- Socket.io
Before we write any code, lets follow the instructions here to make sure your Discord application is set up correctly.
In this directory (/examples/asteroids-rivet
) we need to create a .env
file with the OAuth2 variables, as described here.
DISCORD_CLIENT_ID=123456789012345678
DISCORD_CLIENT_SECRET=abcdefghijklmnopqrstuvwxyzabcdef
First, we deploy the game to Rivet with the Rivet CLI. See how to install the Rivet CLI here.
After installation, run this command to get your project linked to Rivet Cloud. You will be asked to sign in and create a game to link to.
rivet init
Next, we can deploy to Rivet:
rivet deploy prod
If successful, you should see a message in your terminal that looks like so:
Deploy Succeeded https://asteroids-xxx.rivet.game/
Using the URL of the successfully deployed game, you can update your activity's URL mappings to match like so:
- Important: The other URL bindings are required for API requests to Rivet.
- More regions can be added by updating the
rivet.yaml
file and adding a new URL mapping in the config. Note that this will not be required once this support request is resolved; you will only need one URL mapping for lobby connections:/ws/{region}/{lobby} -> {lobby}.lobby.{region}.rivet.run
Finally, you can follow the guide here on getting the activity running in Discord.