Discord Integration Guide - Getting Started

Build games and experiences that run inside Discord


Overview

AeThex can be embedded as a Discord Activity, allowing users to access your games directly within Discord servers. This guide will help you integrate Discord Activity into your AeThex game in 5 minutes.

What is a Discord Activity?

A Discord Activity is an embedded application that runs within Discord. With AeThex Discord integration, you can:

  • ✅ Launch your game directly inside Discord servers

  • ✅ Share real-time experiences with server members

  • ✅ Authenticate users seamlessly with Discord OAuth

  • ✅ Enable voice chat and collaboration without leaving Discord

  • ✅ Reach Discord's 150M+ active users

Architecture Overview

User in Discord Server

Launches AeThex Activity

Your Game loads in Discord iframe

AeThex SDK handles authentication & state

Your game logic runs normally

Prerequisites

Before you begin, ensure you have:

  • Discord Application registered at Discord Developer Portalarrow-up-right

  • HTTPS domain (Discord Activities require SSL/TLS)

  • AeThex account with API credentials

  • Node.js 18+ installed for development

Note: Discord Activities do NOT work with IP addresses or localhost (except for local SDK testing). You must use a proper domain.


Quick Start (5 minutes)

Step 1: Enable Discord Activity in Developer Portal

  1. Select your application (or create a new one)

  2. Navigate to General Information tab

  3. Scroll to Activity Settings section

  4. Click Enable Activities (if not already enabled)

  5. Set Activity URL to: https://yourdomain.com/discord

  6. Set Interactions Endpoint URL to: https://yourdomain.com/api/discord/interactions

  7. Click Save Changes

Step 2: Configure OAuth2 Redirect URIs

  1. In Discord Developer Portal, go to OAuth2 tab

  2. Under Redirects, add:

  3. Under OAuth2 Scopes, ensure these are enabled:

    • identify (read user profile)

    • email (read user email)

    • guilds (see servers user is in)

  4. Click Save Changes

Important: Wait 1-2 minutes for Discord to propagate your changes.

Step 3: Install AeThex SDK

Step 4: Configure Environment Variables

Create a .env file in your project root:

Security Note: Never commit CLIENT_SECRET or SERVICE_ROLE keys to version control.

Step 5: Create Discord Activity Page

Create a new page at /discord in your app:

Step 6: Add Route

In your router configuration:

Step 7: Test Your Activity

  1. Add your bot to a test Discord server:

    • Go to Discord Developer Portal → OAuth2URL Generator

    • Select scopes: bot, applications.commands

    • Copy the generated URL and paste in browser

    • Select a test server and authorize

  2. Launch the Activity:

    • In Discord, click on your bot

    • Look for "Activities" or right-click → Apps

    • Select your Activity

    • It should open in a modal within Discord

  3. Verify it works:

    • Open browser console (F12)

    • Check for "Discord SDK is ready!" message

    • Verify no errors


Authentication Flow

Discord Activities use OAuth2 for user authentication. Here's how it works:

1. User Flow

2. Implementation Example


Detecting Discord Activity Context

Your app should detect when it's running inside Discord and adjust the UI accordingly:


Account Linking

Allow users to link their existing AeThex account with Discord:

Users can link Discord from their account settings:

If you have a Discord bot, users can type /verify in Discord to get a linking code:

  1. User types /verify in Discord

  2. Bot generates a 6-digit code

  3. User visits yourdomain.com/discord-verify?code=123456

  4. Account is linked automatically

Implementation example in Discord Activity Reference.


Best Practices

✅ Do's

  • Always use HTTPS - Discord requires secure connections

  • Handle authentication errors gracefully - Show helpful error messages

  • Optimize for Discord's iframe size - Test responsive layouts

  • Cache Discord user data - Reduce API calls

  • Test on multiple devices - Desktop and mobile Discord apps

❌ Don'ts

  • Don't use IP addresses - Discord won't load your Activity

  • Don't store tokens in localStorage - Use secure HTTP-only cookies

  • Don't assume all users have Discord - Support web login too

  • Don't make excessive API calls - Respect rate limits

  • Don't forget error handling - Network issues happen


Common Issues & Solutions

Issue: "Could not fetch application data"

Cause: Activities feature not enabled or Activity URL not set

Solution:

  1. Go to Discord Developer Portal

  2. Enable Activities in General Information

  3. Set Activity URL to your domain

  4. Wait 2 minutes for changes to propagate

Issue: "Failed to authenticate"

Cause: OAuth redirect URI not registered

Solution:

  1. Go to Discord Developer Portal → OAuth2

  2. Add your callback URL: https://yourdomain.com/api/discord/oauth/callback

  3. Save and wait 2 minutes

Issue: "Session lost during OAuth"

Cause: Cookies not being sent with OAuth callback

Solution:

  1. Ensure your API domain matches your frontend domain

  2. Set cookies with SameSite=Lax or SameSite=None; Secure

  3. Verify OAuth callback URL is EXACTLY as registered in Discord portal

For more troubleshooting tips, see Discord Deployment Guide.


Next Steps

Now that you have Discord Activity integrated, explore these advanced features:


Need Help?


Last Updated: January 7, 2026 AeThex SDK Version: 2.0+ Discord SDK Version: 1.0+

Last updated