-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (30 loc) · 975 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Require classes
const { Client, GatewayIntentBits } = require('discord.js');
const Helper = require('./module/helper.js');
const { GameDig } = require('gamedig');
require('dotenv').config();
//Load env
const token = process.env.DISCORD_TOKEN;
const server_host = process.env.SRCDS_HOST;
const server_port = process.env.SRCDS_PORT;
const server_game = process.env.SRCDS_GAME;
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once('ready', () => {
console.log('Discord bot ready!');
getServerStatus();
});
client.login(token);
//Presence updating logic
function getServerStatus() {
GameDig.query({
type: server_game,
host: server_host,
port: server_port
}).then((state) => {
Helper.setBotPresence(client,state.players.length,state.bots.length,state.maxplayers,state.map);
}).catch((error) => {
console.log(`Error setting presence, error: ${error}`);
});
setTimeout(getServerStatus, 1000*10);
}