From fdb47b998d896a1af64516bc64b42172bae114d3 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Wed, 5 Nov 2025 07:32:41 +0000 Subject: [PATCH] Discord Activity Wrapper Page cgen-22bf7512a16245b4a6db40df9fa79d58 --- client/pages/DiscordActivity.tsx | 131 +++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 client/pages/DiscordActivity.tsx diff --git a/client/pages/DiscordActivity.tsx b/client/pages/DiscordActivity.tsx new file mode 100644 index 00000000..f082de1a --- /dev/null +++ b/client/pages/DiscordActivity.tsx @@ -0,0 +1,131 @@ +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 ( +
+
+

👋 Welcome {discordUser.username} to AeThex Discord Activity

+
+ +
+ ); +}