import { useEffect, useState } from 'react'; import { useDiscord } from '@/contexts/DiscordContext'; import LoadingScreen from '@/components/LoadingScreen'; interface DiscordSDK { ready: () => Promise; user: { getMe: () => Promise; }; commands: { authorize: (options: any) => Promise; }; } export default function DiscordActivity() { const { isDiscordActivity, discordUser } = useDiscord(); const [sdkReady, setSdkReady] = useState(false); const [error, setError] = useState(null); useEffect(() => { const initDiscordSDK = async () => { try { // Discord SDK should be loaded by the script in index.html if (!(window as any).DiscordSDK) { throw new Error('Discord SDK not loaded'); } const discord = (window as any).DiscordSDK as DiscordSDK; // Ready the SDK await discord.ready(); setSdkReady(true); // Subscribe to close events if (discord.subscribe) { discord.subscribe('ACTIVITY_INSTANCE_PARTICIPANTS_UPDATE', (data: any) => { console.log('Discord participants updated:', data); }); } } catch (err) { const errorMessage = err instanceof Error ? err.message : String(err); console.error('Failed to initialize Discord SDK:', err); setError(errorMessage); } }; if (!sdkReady) { initDiscordSDK(); } }, []); if (error) { const isCloudflareError = error.includes('Direct IP access') || error.includes('Error 1003'); const isSDKError = error.includes('Discord SDK'); return (

Connection Error

Unable to initialize Discord Activity

{error}

{isCloudflareError && (

🌐 Cloudflare Blocking Access

This error occurs when accessing AeThex via an IP address. Please access through the proper domain:

https://aethex.dev/discord
)} {isSDKError && (

🎮 Discord SDK Issue

Make sure you're opening this as a Discord Activity within a Discord server, not as a standalone website.

)}

Troubleshooting steps:

  • Access via domain: aethex.dev/discord
  • Open in Discord Activity, not as regular website
  • Ensure Discord server has AeThex Activity installed
  • Try refreshing the Discord window
); } if (!isDiscordActivity || !sdkReady) { return ( ); } if (!discordUser) { return (

Welcome to AeThex

Discord user information unavailable

); } // Activity is ready and user is authenticated via Discord return ( ); }