Discord Bot for use with Crafty4 Minecraft Servers
  • Python 95.6%
  • Dockerfile 4.4%
Find a file
2026-03-01 18:14:36 -05:00
.github/workflows ci: publish docker image to ghcr.io on successful build 2026-03-01 18:04:26 -05:00
cogs feat: Introduce unit testing with pytest and enhance Crafty API client with configurable SSL verification. 2026-03-01 17:44:47 -05:00
tests style: fix remaining formatting and linting issues in test files 2026-03-01 17:55:36 -05:00
.dockerignore refactor: modularize Minecraft commands into a cog, abstract Crafty API interactions, and centralize configuration. 2026-03-01 16:23:55 -05:00
.gitignore Added .gitignore 2025-12-26 10:01:38 -05:00
.python-version ci: fix missing .python-version error 2026-03-01 17:51:25 -05:00
bot.py feat: Introduce unit testing with pytest and enhance Crafty API client with configurable SSL verification. 2026-03-01 17:44:47 -05:00
config.py feat: Introduce unit testing with pytest and enhance Crafty API client with configurable SSL verification. 2026-03-01 17:44:47 -05:00
crafty_api.py feat: Introduce unit testing with pytest and enhance Crafty API client with configurable SSL verification. 2026-03-01 17:44:47 -05:00
docker-compose-build.yml Aded build yaml, changed README, changed yaml for prebuilt image 2025-12-26 16:19:05 -05:00
docker-compose.yml docs: update docker instructions to use ghcr.io image 2026-03-01 18:04:47 -05:00
Dockerfile refactor: Migrate to uv for dependency management and ruff for code quality, updating Dockerfile, project configuration, and documentation. 2026-03-01 16:53:24 -05:00
example.env feat: Implement server configuration via JSON file or environment variable, deprecating the legacy environment variable pattern. 2026-03-01 16:35:42 -05:00
LICENSE Initial commit 2025-12-26 09:18:07 -05:00
pyproject.toml feat: Introduce unit testing with pytest and enhance Crafty API client with configurable SSL verification. 2026-03-01 17:44:47 -05:00
README.md docs: clarify ghcr.io deployment instructions 2026-03-01 18:14:36 -05:00
servers.json.example feat: Implement server configuration via JSON file or environment variable, deprecating the legacy environment variable pattern. 2026-03-01 16:35:42 -05:00
uv.lock feat: Introduce unit testing with pytest and enhance Crafty API client with configurable SSL verification. 2026-03-01 17:44:47 -05:00

Crafty Discord Bot

A Discord slash-command bot for querying and controlling Minecraft servers managed by Crafty Controller on GitLab.

This bot supports multiple servers, role-based permissions, and runs cleanly in Docker.

This project is not affiliated with the Crafty Controller team; it simply uses their public API.

This is a personal project shared publicly. I may not respond to issues or feature requests.


Features

  • /mc slash command with action choices:
    • Status
    • Start
    • Stop
    • Restart
  • Supports multiple Minecraft servers
  • Optionally restricts which Discord roles can control servers
  • Works in a single Discord channel or globally
  • Compatible with reverse proxies and containerized environments
  • Optional HTTP health endpoint for container orchestration

Requirements

  • Discord Bot Token
  • Discord bot permissions / scopes
    • OAuth2 scopes: bot, applications.commands
    • No privileged intents are required for basic slash-command usage
  • Crafty Controller API Token
  • Crafty Controller URL
  • Python 3.11+ and uv (recommended for local runs) or Docker

Crafty must have API access enabled.


Installation

Docker Compose

Step 1 — Download the required files

Create a folder and go into it:

mkdir mc-discord-bot && cd mc-discord-bot

Download the Docker Compose file:

wget -O docker-compose.yml https://raw.githubusercontent.com/owlburtoe/mc-discord-bot/main/docker-compose.yml

and the environment template:

wget -O .env https://raw.githubusercontent.com/owlburtoe/mc-discord-bot/main/example.env

Step 2 — Configure

Open .env in your editor and populate it with your values:

  • PUID/PGID (REQUIRED for Crafty to run properly!!)
  • Discord bot token
  • Crafty URL and token

Download the servers template:

wget -O servers.json https://raw.githubusercontent.com/owlburtoe/mc-discord-bot/main/servers.json.example

Open servers.json in your editor and define your servers.

Step 3 — Start the bot

The docker-compose.yml file is configured to automatically download the latest secure build directly from the GitHub Container Registry (ghcr.io).

Bring it online:

docker compose up -d

Note: If you are making modifications and prefer to build the bot locally from source rather than pulling the pre-built image, you can use docker-compose-build.yml instead.

The bot won't fully start until all the required variables in .env are entered. Crafty will begin to run as long as PUID/PGID and TZ are provided.

To view logs:

docker compose logs -f

Step 4 - Visit Crafty4

Development

This project uses ruff for lightning-fast linting and formatting.

🧹 Linting

To check for issues and automatically fix what's possible:

uv run ruff check --fix .

Formatting

To format the codebase:

uv run ruff format .

License

  • You do not edit the container image
  • You update configuration only through .env
  • Recreate the container when .env changes

Configuration

The bot is configured entirely through environment variables.

See example.env for a complete template.

Discord configuration

Variable Description
DISCORD_TOKEN Bot token from Discord Developer Portal
GUILD_ID Optional: Restrict slash commands to one guild
ALLOWED_CHANNEL_ID Optional: Channel ID where commands are allowed/wanted
OWNER_ID Discord user ID with FULL permissions
MOD_ROLE_ID Role allowed control actions

Crafty Controller configuration

Variable Description
CRAFTY_URL Base URL of your Crafty Controller
CRAFTY_TOKEN API token made in Crafty

Defining Minecraft servers

The recommended way to define servers is using a servers.json file.

servers.json format:

[
  {
    "key": "surv",
    "name": "Survival",
    "id": "00000000-0000-0000-0000-000000000001"
  },
  {
    "key": "crea",
    "name": "Creative",
    "id": "00000000-0000-0000-0000-000000000002"
  }
]

Copy servers.json.example to servers.json and edit.

Alternate: Environment Variable

You can also provide server definitions as a JSON string in the MC_SERVERS_JSON environment variable.

Legacy Method (Deprecated)

Servers can be mapped by index using the following pattern: MC_SERVER_<N>_KEY, MC_SERVER_<N>_NAME, MC_SERVER_<N>_ID.

Example: MC_SERVER_1_KEY=surv MC_SERVER_1_NAME=Survival MC_SERVER_1_ID=00000000-0000-0000-0000-000000000001

Slash Command Usage

In Discord: /mc

Actions:

  • 📊 Status
  • ▶️ Start
  • ⏹️ Stop
  • 🔁 Restart

Server names match the values defined in your environment file.

Health Check Endpoint (optional)

GET /health

Response example:

{
  "status": "ok",
  "servers": 3
}

Enable by exposing port 8085 in Docker if needed by your orchestrator.


Common Issues

Commands not showing up

  • Ensure the bot has application.commands scope
  • If using GUILD_ID, the guild must match your server
  • Wait a few minutes for global command propagation

“Unknown server”

  • Key/name mismatch between .env and command
  • Incorrect server UUID

401 / Crafty API failure

  • API token invalid
  • Crafty URL incorrect
  • HTTPS certificate issues if using self-signed certs