eco-discord-bot/src/index.ts
2022-12-31 15:44:08 +12:00

31 lines
872 B
TypeScript

import dotenv from 'dotenv';
import { ActivityType, Client, GatewayIntentBits } from 'discord.js'
import { queryGameServerInfo } from 'steam-server-query';
import axios from 'axios';
dotenv.config()
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user?.tag}!`);
updateServerData();
setInterval(updateServerData, 10000)
});
async function updateServerData() {
try {
const { data } = await axios.get<any>(`${process.env.ECO_API_BASE || "https://eco.kamgames.xyz"}/info`);
client.user?.setActivity({
name: `${data.OnlinePlayers}/${data.TotalPlayers}`,
type: ActivityType.Playing
})
} catch (e) {
client.user?.setActivity({
name: `Сервер офлайн`,
type: ActivityType.Playing
})
}
}
client.login(process.env.DISCORD_TOKEN);