Introduction
In this guide, you will build a Discord app with a basic Activity that handles user authentication and fetches data using the Discord API. This guide assumes familiarity with JavaScript, async functions, and frontend frameworks like React or Vue.Resources used in this guide
Resources used in this guide
- discord/getting-started-activity — a project template to get you started
- @discord/embedded-app-sdk — the SDK for communication between your app and Discord
- Node.js — latest version
- Express — a JavaScript web framework for handling authentication and serving your app
- Vite — a build tool for modern JavaScript projects
- cloudflared — for bridging your local development server to the internet
Step 0: Enable Developer Mode
Before getting started, enable Developer Mode on your Discord account. Developer Mode lets you run in-development Activities and exposes resource IDs in the Discord client to simplify testing.Open User Settings
In your Discord client, click the cogwheel icon near the bottom-left next to your username.
Step 1: Set Up the Project
Clone thediscord/getting-started-activity repository:
client— the Activity’s frontend, built with vanilla JavaScript and Viteserver— a backend using Node.js and Express for handling authentication
Project structure
Project structure
client directory and install dependencies:
http://localhost:5173/ to see the frontend template running.
Step 1 Checkpoint
Step 1 Checkpoint
By the end of Step 1, you should have:
- Developer Mode enabled on your Discord account
- The sample project cloned locally
- Frontend dependencies installed and the dev server running
Step 2: Create a Discord App
Create a new app in the developer portal: Create App Enter a name, select a team, and click Create.Launching a non-distributed Activity is limited to you and members of the developer team. If collaborating with others, create a developer team and set it as the owner.
Configure Installation Contexts
Click Installation in the sidebar and make sure both User Install and Guild Install are selected under Installation Contexts. This ensures users can launch your Activity across servers, DMs, and Group DMs.Add a Redirect URI
The Embedded App SDK automatically handles redirecting users back to your Activity, but you need to register at least one Redirect URI. Click OAuth2, enterhttps://127.0.0.1 as a placeholder redirect URI, and click Save Changes.
Copy Your OAuth2 Credentials
In the root of your project, copy the environment file template:- Copy Client ID into your
.envasVITE_CLIENT_ID - Copy Client Secret into your
.envasDISCORD_CLIENT_SECRET
The
VITE_ prefix makes the variable accessible to client-side code. All other environment variables remain private. See the Vite documentation for details.Step 2 Checkpoint
Step 2 Checkpoint
By the end of Step 2, make sure you have:
- A placeholder Redirect URI set in your app’s OAuth2 settings
- Your app’s Client ID and Client Secret added to your
.envfile
Step 3: Set Up the Embedded App SDK
Install the Embedded App SDK in your project’sclient directory:
getting-started-activity/client/main.js to import and instantiate the SDK:
Step 3 Checkpoint
Step 3 Checkpoint
By the end of Step 3, make sure you have:
- Installed the Embedded App SDK
- Imported and instantiated the SDK in
client/main.js
Step 4: Run Your App in Discord
Start the Frontend
In yourclient directory:
Set Up a Public Endpoint
Activities must be served over a public HTTPS URL. Usecloudflared to create a tunnel:
Configure URL Mapping
In your app’s settings, click URL Mappings under Activities. Enter thecloudflared URL as the target for the / prefix:
| PREFIX | TARGET |
|---|---|
/ | funky-jogging-bunny.trycloudflare.com |
Enable Activities
Under Activities in the sidebar, click Settings and toggle on Enable Activities. When Activities are enabled, a default Entry Point command called “Launch” is automatically created.Launch in Discord
Navigate to a voice or text channel and open the App Launcher. Your Activity should appear — click it to launch your locally running app from inside Discord.Step 4 Checkpoint
Step 4 Checkpoint
By the end of Step 4, make sure you have:
- A running public endpoint via
cloudflared - A URL Mapping configured in your app’s settings
- Activities enabled for your app
- Successfully launched your Activity in Discord
Step 5: Authorize and Authenticate Users
Start the backend server to handle the OAuth2 flow:POST /api/token route that exchanges an authorization code for an access token.
server/server.js
server/server.js
client/main.js to perform the full authorization and authentication flow:
Step 5 Checkpoint
Step 5 Checkpoint
By the end of Step 5, make sure you have:
- Updated
client/main.jsto call the backend for user authorization and authentication - Successfully completed the authorization flow when launching your Activity
Step 6: Fetch the Channel with the SDK
Now that users are authenticated, use the SDK to fetch information about the channel the Activity is running in:Step 7: Fetch the Guild Using the API
With theguilds scope granted, you can use the access_token to call the Discord HTTP API directly:
Next Steps
You now have a working Discord Activity that authenticates users and fetches Discord data. From here, explore:Development Guides
Learn about local development setup, networking, multiplayer patterns, and more.
SDK Reference
Full reference for all Embedded App SDK commands and events.
Sample Projects
Explore the full range of SDK features in the playground app and other examples.