Skip to content

cxve/discord-activity-react-websocket-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discord-activity-react-websocket-template

Woah, that's a mouthful, huh? And I didn't even mention TypeScript!

Since there are a lot of steps involved in making a Discord Activity, I decided to create this template as a starting point for anyone like me, who wants to create activities with react and websockets. It is based on the net code I wrote for my very first Discord Activity which I ended up liking so much that I also used similar implementations for my other activities.

What's included in this template?

  • Discord Embedded App SDK
  • React + Vite + Typescript Template
  • Working websocket client and server
  • Completed authentication flow

Where to get started?

Start by getting the authentication flow to work with your Discord app! Discord's Guide "Building Your First Activity in Discord" goes into more detailed, but here's an abridged version:

  1. Enable Developer Mode on Discord
  2. Create an App on Discord
  3. In OAuth2 add https://127.0.0.1 as redirect
  4. Add your proxy in the Activity URL Mappings
  5. Enable Activities in your app
  6. Rename .env_template to .env and add your app's ID and secret
  7. Add the host of your proxy in client/vite.config.ts
  8. Start client and server (see below)
  9. Start your activity on Discord

This is what it should look like in the end! Screenshot of React + Vite Template which includes the user's avatar and display name

Throughout the code, I marked places of interest. For example, in server/src/close.ts I marked the place where you would put user disconnection logic with YOU: put player disconnection logic in here!. Just search the repository for comments starting with YOU:!

How to start the client and server?

The client and server are two separate packages and as such must be installed and started individually. Open both the client as well as the server folder, run npm install and then npm run dev. For the client, you may need to run npm run dev -- --host instead, to make it accessible from the internet.

I also included an example launch.json for vscode with the run commands and a placeholder for a reverse proxy. Any reverse proxy should do, but I managed to get this setup working for ngrok, ssh, and frp each.

About

This template is my ideal starting place for all my Discord Activities that require websockets (so far: all of them!)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors