changed to different api
This commit is contained in:
@@ -8,32 +8,43 @@ module.exports = {
|
|||||||
.setDescription('Get the current server status and players'),
|
.setDescription('Get the current server status and players'),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const SERVER_IP = `${server_ip}`;
|
const serverURL = `https://api.mcstatus.io/v2/status/java/${server_ip}`
|
||||||
try {
|
let embedData;
|
||||||
axios.get(`https://api.mcsrvstat.us/3/${SERVER_IP}`).then((resp) => {
|
axios.get(serverURL)
|
||||||
const data = resp.data;
|
.then((response) => {
|
||||||
|
const data = response.data;
|
||||||
const embedData = {
|
console.log(data.players.list)
|
||||||
title: SERVER_IP,
|
if (data.online === true){
|
||||||
|
embedData = {
|
||||||
|
title: server_ip,
|
||||||
description: data.online ? 'Server is online' : 'Server is offline',
|
description: data.online ? 'Server is online' : 'Server is offline',
|
||||||
color: data.online ? 0x00FF00 : 0xFF0000,
|
color: data.online ? 0x00FF00 : 0xFF0000,
|
||||||
fields: [
|
fields: [
|
||||||
{ name: 'Version', value: `${data.version} (Protocol ${data.protocol.version})`, inline: false },
|
{ name: 'Version', value: `${data.version.name_clean} (Protocol ${data.version.protocol})`, inline: false },
|
||||||
],
|
],
|
||||||
footer: { text: `${data.players.online}/${data.players.max} players` },
|
footer: { text: `${data.players.online}/${data.players.max} players` },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.players && data.players.list && data.players.list.length > 0) {
|
if (data.players && data.players.list && data.players.list.length > 0) {
|
||||||
embedData.fields.push({ name: 'Player List', value: data.players.list.map(player => player.name).join('\n'), inline: false });
|
embedData.fields.push({ name: 'Player List', value: data.players.list.map(player => player.name_clean).join('\n'), inline: false });
|
||||||
} else {
|
} else {
|
||||||
embedData.fields.push({ name: 'Player List', value: 'No players online :(', inline: false });
|
embedData.fields.push({ name: 'Player List', value: 'No players online :(', inline: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
embedData = {
|
||||||
|
title: SERVER_IP,
|
||||||
|
description: data.online ? 'Server is online' : 'Server is offline',
|
||||||
|
color: data.online ? 0x00FF00 : 0xFF0000,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const embed = new EmbedBuilder(embedData);
|
const embed = new EmbedBuilder(embedData);
|
||||||
interaction.reply({ content: 'Server status:', embeds: [embed] });
|
interaction.reply({ content: 'Server status:', embeds: [embed] });
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error:', error.message);
|
||||||
});
|
});
|
||||||
} catch (e){
|
|
||||||
await interaction.reply("An Error Occurred, and i am too lazy to add a proper embed for it. the server is probably offline or something")
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
0
startBot.sh
Normal file → Executable file
0
startBot.sh
Normal file → Executable file
Reference in New Issue
Block a user