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) { return (

Discord Activity Error

{error}

Make sure you're running this as a Discord Activity within a Discord server.

); } if (!isDiscordActivity || !sdkReady) { return ( ); } if (!discordUser) { return (

Welcome to AeThex

Discord user information unavailable

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