Discord Activity SPA Implementation Guide
Overview
This document describes the isolated Discord Activity implementation for AeThex. The Activity is now a true Single-Page Application (SPA) that runs entirely within Discord's iframe and complies with Discord's Activity requirements.
Architecture
Isolated SPA Pattern (Option A)
The Activity is completely isolated from the main AeThex app:
Discord Client
↓
└─→ Activity Iframe (SPA)
├─ Discord SDK initialization
├─ OAuth flow via postMessage
├─ User profile display
├─ Realm/Arm information
└─ Quick action buttons (open in new window)
↓
└─→ Main App (https://aethex.dev) opens in new tabKey Changes from Previous Implementation
1. Removed Router Navigation
Before: Activity used
useNavigate()to redirect within React RouterAfter: Activity is completely self-contained, no internal navigation
2. Links Now Open in New Windows
Before:
<a href="/creators">navigated within the iframeAfter:
<button onClick={() => window.open(url, "_blank")}>opens the main app in a new tabThis allows users to see full features without breaking Activity isolation
3. Simplified Manifest
Before: Manifest referenced multiple domains including aethex.dev
After: Manifest ONLY references Discord proxy domain (
578971245454950421.discordsays.com)This ensures Activity is properly sandboxed through Discord's proxy
File Changes
code/client/pages/Activity.tsx
Removed:
Added:
Link Changes:
code/public/discord-manifest.json
Before:
After:
Discord Compliance
✅ What This Implementation Does Right
True SPA - Activity never navigates away from itself
Proper Iframe Isolation - No breaking out of Discord's sandbox
PostMessage Protocol - Uses Discord SDK which handles postMessage communication
Proxy Domain Only - Manifest restricted to Discord proxy domain
No External Navigation - Links open in new windows, don't break the Activity
⚠️ Important Limitations
Activity is Read-Only for Display - Can't directly modify the main app from Activity
No Shared Navigation - Activity can't control main app routing
Data Sync Limitation - Activity shows cached/API data, not real-time main app state
URL Mappings Required - Any external resources accessed by Activity need URL mappings in manifest
Testing the Activity
Prerequisites
Have a Discord server where you're an admin
Have registered the AeThex application on Discord Developer Portal
Have installed the AeThex bot in your test server
Local Testing
Start the dev server:
Open Discord and find an Activity that can be launched
Right-click on a voice channel
Select "Launch Activity"
Look for "AeThex Activity"
Expected behavior:
Activity loads without errors
User profile displays correctly
Buttons open links in new tabs (not navigate within Activity)
Discord commands still work (
/profile,/set-realm, etc.)
Deployment Testing
After deploying to production:
Update Discord Developer Portal with production URL
Test in Discord with production URL
Future Enhancements
Expanding Activity Features Without Breaking SPA
If you want to add more features to the Activity without breaking isolation, use the Nested Messages Pattern:
URL Mappings for External Resources
If Activity needs to access external APIs, update the manifest:
Then in code, use relative paths:
Troubleshooting
Activity Won't Load
Check browser console for
[Discord Activity]logsVerify frame_id in URL - should be present in Discord iframe
Check CORS settings - Activity may be blocked by CORS policies
Verify manifest - Make sure manifest.json is served correctly
Links Not Working
Ensure target="_blank" or window.open() - Regular navigation breaks Activity
Check URL construction - Verify full URL is correct
Test in separate browser tab - Verify links work outside Activity
User Profile Not Loading
Check /api/discord/activity-auth endpoint
Verify Supabase integration - User data must exist in database
Check token expiry - OAuth token may have expired
Configuration Checklist
Related Documentation
DISCORD-ACTIVITY-SETUP.md - Initial setup guide
DISCORD-ADMIN-COMMANDS-REGISTRATION.md - Bot commands
Last updated
