ServerEvents.commandRegistry(event => {
    const { commands: Commands } = event
    const DISCORD_LINK = "https://discord.gg/mQDRt67ySB" 
    const COOLDOWN_KEY = "lastDiscordTime"
    event.register(
        Commands.literal('discord')
        .requires(src => src.hasPermission(0))
        .executes(ctx => {
            const player = ctx.source.player
            if (!player) return 0
            const now = Date.now()
            const cooldown = 1000
            const lastUsed = player.persistentData[COOLDOWN_KEY] || 0
            if (now - lastUsed < cooldown) {
                const remaining = ((cooldown - (now - lastUsed)) / 1000).toFixed(1)
                player.tell(`§cYou must wait §e${remaining}s §cbefore using this command again!`)
                return 0
            }
            player.persistentData[COOLDOWN_KEY] = now
            const server = ctx.source.server
            const discordMessage = [
                "",
                { "text": "\u2560\u2550\u2550\u2550\u2563", "color": "gold" },
                { "text": "DISCORD", "bold": true, "color": "blue" },
                { "text": "\u2560\u2550\u2550\u2550\u2563", "color": "gold" },
                { "text": "\n\n \u0020 " },
                { 
                    "text": "Click Here To Join", 
                    "bold": true, 
                    "underlined": true, 
                    "color": "green", 
                    "clickEvent": { "action": "open_url", "value": DISCORD_LINK } 
                },
                { "text": "\n\n" },
                { "text": "\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563", "color": "gold" }
            ];
            const rawCommand = `/tellraw @a ${JSON.stringify(discordMessage)}`
            server.runCommandSilent(rawCommand)
            return 1
        })
    )
})