LemonHost Blog

Back to Blogs
Author: LemonHost Devs Estimated Read: 5 min Category: Integration

Integrating Your Discord Bot with Minecraft

If you host both a Discord bot and a Minecraft server, connecting them can make community management much easier. You can show server status, mirror chat, or even run admin commands from Discord when you need to.

1. Start with server status

The easiest integration is a status check. Your bot sends a request to a Minecraft status API, then displays whether the server is online, how many players are connected, and what version is running.

This works well if you just want a /status command or a channel message that updates automatically.

Why this is the best first step

Example API flow

Your bot makes a request to a service such as mcstatus.io or api.mcsrvstat.us, then reads the JSON response.

require('dotenv').config();
const fetch = require('node-fetch');

async function getServerStatus(ip) {
  const response = await fetch(`https://api.mcstatus.io/v2/status/java/${ip}`);
  if (!response.ok) throw new Error(`Status API returned ${response.status}`);

  const data = await response.json();
  return {
    online: !!data.online,
    players: data.players?.online ?? 0,
    motd: data.motd?.clean ?? '',
    version: data.version?.name ?? ''
  };
}

2. Use a chat bridge if you want live messages

If you want Minecraft chat to appear in Discord, or Discord chat to show up in Minecraft, you need a bridge. For Java servers, the easiest option is usually DiscordSRV.

If you prefer custom code, libraries such as minecraft-server-util can help you query the server without installing a plugin.

3. Use RCON for admin commands

RCON lets your bot run server-side console commands such as list, save-all, or restart. This is useful when you want to control the Minecraft server from Discord.

Security should come first

Example environment variables:

MC_IP=your-server-ip
RCON_PORT=25575
RCON_PASSWORD=your-strong-password

Example Node.js RCON code:

require('dotenv').config();
const { Rcon } = require('rcon-client');

async function runRconCommand(cmd) {
  const conn = await Rcon.connect({
    host: process.env.MC_IP,
    port: Number(process.env.RCON_PORT || 25575),
    password: process.env.RCON_PASSWORD
  });

  try {
    return await conn.send(cmd);
  } finally {
    await conn.end();
  }
}

runRconCommand('list').then(console.log).catch(console.error);

What to build first

If you are deciding where to start, build the status command first. It is the easiest feature to ship and gives your users an immediate win. After that, add either a chat bridge or RCON commands depending on what your community actually needs.

Good rule of thumb: start small, secure the sensitive parts, and only add deeper integration if it solves a real problem for your users.