require("dotenv").config(); const { Client, GatewayIntentBits, EmbedBuilder } = require("discord.js"); const axios = require("axios"); const client = new Client({ intents: [ GatewayIntentBits.Guilds ] }); const services = [ { name: "Website", url: "https://vyla.cc" }, { name: "Player", url: "https://player.vyla.cc" }, { name: "API", url: "https://api.vyla.cc" } ]; let statusMessage; async function checkService(service) { const start = Date.now(); try { const response = await axios.get(service.url, { timeout: 10000 }); return { online: true, latency: Date.now() - start, status: response.status }; } catch { return { online: false, latency: null, status: null }; } } async function updateStatus() { const channel = await client.channels.fetch( process.env.CHANNEL_ID ); let description = ""; let allOnline = true; for (const service of services) { const result = await checkService(service); if (!result.online) allOnline = false; description += ` **[${service.name}](${service.url})** Status: ${result.online ? "🟢 Online" : "🔴 Offline"} Response Time: ${result.latency ?? "N/A"} ms `; } const embed = new EmbedBuilder() .setTitle( allOnline ? "All Systems Operational" : "System Issues Detected" ) .setDescription(description) .setColor( allOnline ? 15987699 : 16711680 ) .setFooter({ text: `Last updated: ${new Date().toLocaleString()}` }); if (!statusMessage) { statusMessage = await channel.send({ embeds: [embed] }); } else { await statusMessage.edit({ embeds: [embed] }); } } client.once("ready", async () => { console.log( `${client.user.tag} is online` ); await updateStatus(); setInterval( updateStatus, 60000 ); }); client.login( process.env.DISCORD_TOKEN );