6.6 KiB
6.6 KiB
Discord Activity Setup Guide
This guide explains how to set up and deploy the AeThex platform as a Discord Activity.
Overview
AeThex can now be embedded as a Discord Activity, allowing users to access the full platform directly within Discord. The integration uses:
- Discord SDK for Activity context detection and user authentication
- Discord OAuth 2.0 for secure user verification
- React Context for managing Discord user state
Prerequisites
- Discord Application ID:
578971245454950421 - Discord Client Secret (from Discord Developer Portal)
- Discord Public Key (from Discord Developer Portal)
- Deployed Application URL:
https://aethex.dev
Configuration Steps
1. Discord Developer Portal Setup
- Go to Discord Developer Portal
- Open your application (ID:
578971245454950421) - Navigate to General Information
- Copy your Public Key and Client Secret and save them securely
- Go to OAuth2 > General and add Redirect URI:
https://aethex.dev/discord/callback
2. Environment Variables
Set these environment variables in your deployment:
For Netlify/Vercel:
VITE_DISCORD_CLIENT_ID=578971245454950421
DISCORD_CLIENT_SECRET=your-client-secret-here
DISCORD_PUBLIC_KEY=your-public-key-here
DISCORD_REDIRECT_URI=https://aethex.dev/discord/callback
For Local Development:
# .env or via DevServerControl
VITE_DISCORD_CLIENT_ID=578971245454950421
DISCORD_CLIENT_SECRET=your-client-secret-here
DISCORD_PUBLIC_KEY=your-public-key-here
PUBLIC_BASE_URL=http://localhost:5173
3. Get Your Public Key
- In Discord Developer Portal, go to General Information
- Copy your Public Key (located in the Application ID section)
- Add it to your environment variables:
DISCORD_PUBLIC_KEY=your-public-key-here
4. Activity Configuration in Discord
In the Discord Developer Portal for your application:
- Go to App Details or General Information
- Find the Interactions Endpoint URL field
- Set it to:
https://aethex.dev/api/discord/interactions - Discord will verify this endpoint automatically
- Once verified, find "Activities" section and set the Activity URL to:
https://aethex.dev/discord
- Enable "Requires OAuth2 Code Grant"
4. Deploy the Application
The application is now ready to be deployed. All changes include:
- Discord Context Provider (
code/client/contexts/DiscordContext.tsx) - Discord Activity Page (
code/client/pages/DiscordActivity.tsx) - OAuth Callback Handler (
code/client/pages/DiscordOAuthCallback.tsx) - API Endpoint (
/api/discord/oauth/callback) - Discord SDK Integration (in
index.html)
How It Works
Activity Flow
- User launches Activity: User opens the Discord Activity in a Discord server
- SDK Initialization:
DiscordContextattempts to load and initialize Discord SDK - User Detection: If in Discord Activity context, user info is retrieved from Discord
- Authentication:
- If in Discord Activity: User is automatically identified via Discord
- If standard OAuth: User is redirected to Discord OAuth flow
- App Access: User gains full access to AeThex platform with Discord credentials
Routes
/discord- Main Discord Activity page/discord/callback- OAuth callback handler (redirects to dashboard)/api/discord/oauth/callback- Backend OAuth token exchange
Usage
For Users
Users can access AeThex as a Discord Activity by:
- Going to their Discord server
- Clicking on "Activities" (rocket icon)
- Searching for or selecting "AeThex"
- Activity launches in the Discord client
For Developers
To integrate Discord authentication in components:
import { useDiscord } from '@/contexts/DiscordContext';
export function MyComponent() {
const { isDiscordActivity, discordUser, initiateDiscordOAuth } = useDiscord();
return (
<div>
{isDiscordActivity ? (
<p>Running as Discord Activity for {discordUser?.username}</p>
) : (
<button onClick={initiateDiscordOAuth}>
Connect with Discord
</button>
)}
</div>
);
}
Troubleshooting
SDK Not Loading
If Discord SDK doesn't load:
- Check that you're running the Activity in Discord (not a web browser)
- Verify the Activity URL is correctly configured in Discord Developer Portal
- Check browser console for SDK loading errors
OAuth Failures
If OAuth fails:
- Verify
DISCORD_CLIENT_SECRETis set correctly - Confirm redirect URI matches Discord Developer Portal settings
- Check server logs for token exchange errors
User Not Detected
If Discord user info isn't available:
- The Activity might not have proper permissions
- User might not be authenticated with Discord
- Check Discord SDK
ready()promise resolved successfully
Security Considerations
- Client Secret: Keep
DISCORD_CLIENT_SECRETsecure (never expose in frontend) - OAuth State: Discord SDK handles state validation automatically
- Redirect URI: Only whitelist your official domain
- Token Storage: OAuth tokens are stored securely in
localStorage - CORS: Discord Activities run in isolated context; standard CORS doesn't apply
API Documentation
POST /api/discord/oauth/callback
Exchanges Discord authorization code for access token.
Request:
{
"code": "authorization_code",
"state": "optional_state_value"
}
Response:
{
"ok": true,
"access_token": "token",
"discord_user": {
"id": "user_id",
"username": "username",
"avatar": "avatar_url",
"email": "user@example.com"
}
}
Final Setup in Discord Developer Portal
- In Discord Developer Portal, go to your application's General Information page
- Find the Interactions Endpoint URL field
- Enter:
https://aethex.dev/api/discord/interactions - Discord will automatically verify this endpoint by sending a PING request
- Once verified, save the changes
- Navigate to the Activities section (or embedded app settings)
- Set the Activity URL to:
https://aethex.dev/discord - Enable "Requires OAuth2 Code Grant" if available
Next Steps
- Set environment variables in your deployment:
DISCORD_CLIENT_SECRETDISCORD_PUBLIC_KEY
- Deploy the application
- Configure the Interactions Endpoint URL in Discord Developer Portal
- Test the Activity in a Discord server
- Monitor logs for any issues
Support
For issues or questions:
- Check Discord Developer Portal documentation: https://discord.dev
- Review error logs in server console
- Contact support@aethex.tech