-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·63 lines (44 loc) · 1.57 KB
/
Copy pathindex.js
File metadata and controls
executable file
·63 lines (44 loc) · 1.57 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const fetch = require('node-fetch');
const rpc = require("discord-rpc")
const client = new rpc.Client({ transport: 'ipc' })
const dotenv = require('dotenv');
dotenv.config();
const rpcdata = require('./src/variables.json');
rpcdata.api_key = process.env.API_KEY
function refreshRPC(rpcdata) {
fetch(`https://top.gg/api/bots/${rpcdata.bot_id}/stats`, {
headers: { "Authorization": rpcdata.api_key }
})
.then(response => response.json())
.then(data => {
if (data && data.server_count) {
let servercount = Number(data.server_count).toLocaleString();
client.request('SET_ACTIVITY', {
pid: process.pid,
activity: {
state: `${servercount} servers`,
details: rpcdata.description,
assets: rpcdata.assets,
buttons: rpcdata.buttons
}
})
} else {
client.request('SET_ACTIVITY', {
pid: process.pid,
activity: {
details: rpcdata.description,
assets: rpcdata.assets,
buttons: rpcdata.buttons
}
})
}
});
}
client.on('ready', () => {
refreshRPC(rpcdata)
setInterval(() => {
refreshRPC(rpcdata)
}, 3600000);
})
client.login({ clientId: rpcdata.bot_id }).catch(console.error);
console.log("[START] Discord RPC with Server Count started!")