This snippet allows you to get information about a Minecraft server you provide the hostname of using a slash command. Make sure to register a slash command named "mc-server-info" via the [command builder](https://autocode.com/tools/discord/command-builder/) with a string option where the server hostname will be passed.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const event = context.params.event;
const sHostname = event.data.options[0].value;
const mcServerData = await lib.http.request['@1.1.6'].get({
url: `https://mcapi.xdefcon.com/server/${sHostname}/full/json`,
});
const data = await mcServerData.data;
// getting the first character of the serverStatus value
const fSC = data.serverStatus[0];
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: process.env.TC_ID,
content: `Hey <@${event.member.user.id}>, here's info for **${sHostname}**!`,
embeds: [
{
title: sHostname,
description: data.motd.text,
fields: [
{
name: 'IP',
value: data.serverip,
},
{
name: 'Version',
value: data.version,
},
{
name: 'Status',
value: data.serverStatus.replace(fSC, 'O'), // replacing the first character of the string with a capital 'O'
},
{
name: 'MS/Ping',
value: data.ping,
},
{
name: 'Online Players',
value: data.maxplayers,
inline: true,
},
{
name: 'Offline Players',
value: data.maxplayers,
inline: true,
},
],
color: 0x55ff55,
},
],
});