-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatus.js
76 lines (67 loc) · 2.4 KB
/
Status.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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
//only change things here
const token = '<discordtoken>';//your discord bot token
const serverip ='<serverIP>';//server ip e.g Play.ThatGuyJack.co.uk
const serverport = 25565;//Set to default port currently change this if yours differs
const serverimage = '<image or gif>';//image for the embeded .status command
const serverurl = '<website';//Your web sites address
const servername = '<Server Name>';//Your server name
const serveredition = 'Java and Bedrock';//put server edition here
const serverver = '1.16.5';//put the server verstion here
//don't edit below unless you know what you are doing
//libs and other vars
const Discord = require('discord.js');
const util = require('minecraft-server-util');
const client = new Discord.Client();
//login
client.login(token);
//print in console when logged in
client.on('ready', () => {
console.log("Logged in.");
});
//create async msg thread to listen for .status
client.on('message', async message => {
if(message.content.toLowerCase() === '.status')
{
console.log(".status");
status(message);
}
});
//function for the embend with the pinger
function status(message){
util.queryFull(serverip, { port: serverport, protocolVersion: 47})
.then((response) => {
console.log(response);
let players = response.players.toString();
if (response.players == "") {
response.players = "No one is Online : (";
}
var colorArray = ["#FF2D00", "#08FF00", "#FFFF00", "#00FFF3", "#005DFF", "#6800FF", "#EC00FF", "#FF0083"];
var randomItem = colorArray[Math.floor(Math.random()*colorArray.length)];
const StatusEmbed = new Discord.MessageEmbed()
.setTitle(servername)
.setURL(serverurl)
.setThumbnail(serverimage)
.addField(`Players Online`,`${response.onlinePlayers}`+ "/" + `${response.maxPlayers}`)
.addField(`Server Version: ${serveredition}`, `${serverver}`)
.addField('Players:',`${response.players}`)
.setColor(`${randomItem}`)
.setTimestamp()
message.channel.send(StatusEmbed);
})
.catch((error) => {
throw error;
});
}
//when bot is logged in set the bots status to the amount of players
client.on('ready', () => {
setInterval(() => {
util.status(serverip, { port: serverport, protocolVersion: 47})
.then((response) => {
console.log(response);
client.user.setActivity(`with ${response.onlinePlayers} players`);
})
.catch((error) => {
throw error;
});
}, 15000);
});