const { Client, Intents, Message} = require('discord.js');
const util = require('minecraft-server-util');
const {EmbedBuilder} = require('discord.js');
const wait = require('util').promisify(setTimeout);
const options = {
timeout: 1000 * 5, // timeout in milliseconds
enableSRV: true // SRV record lookup
};
const prefix = "!mcstatus"; //prefix
const client = new Client({
intents: [
"Guilds",
"GuildMessages",
"MessageContent"
]
});
#Djs V14 setStatus and setPresence dont work
13 messages · Page 1 of 1 (latest)
client.on('ready',() => {
console.log('Status Check Online');// so you know the bot started
client.user.setStatus('idle');
client.user.setPresence({ activities: [{ name: ${server_ip}, type: 'WATCHING' }], status: 'active' });// just a little feature to display whatever server is under server_ip
});
const server_ip = "held-corp.craft.playit.gg";
const server_port = 25565; // replace with the real port also thanks dashcruft for testing the code
client.on('messageCreate', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if(message.content.startsWith(prefix)){
util.status(server_ip, server_port, options)
.then((result) => {
const string1 = JSON.stringify(result)
const string = JSON.parse(string1);
const embed = new EmbedBuilder()
.setColor("#00008B")
.setTitle("Status Server")
.setDescription(`Mai jos sunt informatii in legatura cu serverul de minecraft \n **IP Server:** ${server_ip} \n **Port Server:** ${server_port}`)
.addFields(
{name:"Versiune", value: `${string.version.name}`},
//{name:"Server Protocol Version", value:`${string.version.protocol}`},
{name:"Players Online", value:`${string.players.online}`},
{name:"Max Players", value:`${string.players.max}`},
{name:"Message of the day", value:`${string.motd.clean}`},
{name:"Latency", value:`${string.roundTripLatency}`},
)
.setTimestamp()
message.channel.send({embeds: [embed]})
})
.catch((error) => {
console.log(error);
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("Status necunoscut")
.setDescription(`Serverul este offline , se restarteaza sau are probleme de conexiune `)
.setTimestamp()
message.channel.send({embeds: [embed]})
})}});
client.login("token");
I cant figure out why it wont update the status or presence
use the ActivityType enum instead of "WATCHING"
Ok I'll try
Man thank you so much it worked
👌