import { Command } from 'discord-akairo'; import { Message, MessageAttachment } from 'discord.js'; import Axios from 'axios'; import { colour } from '../../Config'; export default class MinecraftServerStatusFun extends Command { public constructor() { super('minecraftserverstatus', { aliases: ['minecraftserverstatus', 'mcss'], category: 'fun', description: { content: 'Check the status of a specified Minecraft server.', usage: '', examples: [ '' ] }, ratelimit: 3, args: [ { id: "ip", prompt: { start: "What is the IP of the server?", optional: false } }, { id: "port", prompt: { start: "What is the port of the server?", optional: true } } ] }); } public async exec(msg: Message, { ip, port }): Promise { const response = ( await Axios(`https://mcapi.us/server/status?ip=${ip}&port=${port}`).catch(err => { console.error(err); return msg.reply('Woops, there was an error with the (https://mcapi.us) API.'); }) //@ts-ignore ).data; if (response.status !== "success") { return msg.reply('Woops, there was an error with the (https://mcapi.us) API.'); } // https://github.com/discordjs/discord.js/issues/2175#issuecomment-538948474 let embed = this.client.util.embed() .setTitle(ip) .setTimestamp(response.last_updated) .setColor(colour) .setThumbnail(`https://eu.mc-api.net/v3/server/favicon/${ip}${port ? ':' : ''}`) if (response.online) { embed.addField("Server Status", "Currently online.", true); embed.addField("Version", response.server.name, true); embed.addField("Members", `${response.players.now}/${response.players.max}`, true); embed.addField("MOTD", `\`\`\`${response.motd}\`\`\``, true); } else if (response.last_online) { embed.addField("Server Status", `Offline. Last seen ${new Date(response.last_online)}`, true); } else { embed.addField("Server Status", "Offline. Never seen online before.", true); } return msg.channel.send(embed); } }