A friendly Telegram bot to start/stop and monitor a Docker Compose–based Minecraft server. Works with vanilla or modded servers and any Compose service name.
See the latest changes in RELEASE_NOTES.md.
- Start/stop server with manual commands
- Background monitor detects auto starts/stops and health changes
- Player-list/status via
rcon-cliwhen available - Uptime sessions and stats persisted to JSON
- Repair tool to reconstruct history from
server_uptime.log
- A Docker Compose Minecraft server. Recommended:
- itzg/docker-minecraft-server: https://github.com/itzg/docker-minecraft-server
- Ensure the container includes
rcon-cli(the itzg image does)
- A Telegram bot token from BotFather
- Create a virtualenv and install deps:
make install
- Configure environment:
- Copy
.env.exampleto.envand fill values - Required:
TELEGRAM_TOKEN,ADMIN_ID,COMPOSE_DIR - Optional:
RCON_SERVICE(Compose service name providingrcon-cli)
- Copy
- Run the bot:
make
.envkeys:TELEGRAM_TOKEN: BotFather tokenADMIN_ID: Your Telegram user id (integer). Use/addto manage other users later.COMPOSE_DIR: Path to your Docker Compose project (directory containingdocker-compose.yml).RCON_SERVICE(optional): Compose service name that providesrcon-cli(defaults to first service detected). Example:mc.MONITOR_INTERVAL(seconds),START_TIMEOUT(seconds),HEALTH_GRACE_SECONDS(seconds)
Note on service name detection:
- To find your Compose service name (for
RCON_SERVICE), run:Ifdocker compose ps --format json | jq -r '.[].Service'
jqis not installed, inspect raw JSON and pick theServicevalue:Setdocker compose ps --format json
RCON_SERVICEto that service name (oftenmc).
Environment is .env-only. See .env.example for all supported variables.
/server_start: Start the server (authorized group chats)/server_stop: Stop the server (authorized group chats)/server_status: Current status + online players when available Note on start confirmation:- The bot sends the "started successfully" confirmation only when the server is actually ready for players (same criteria as
/server_statusreporting "running"). This avoids premature confirmations when the container is merely up but not yet joinable. /server_logs: Tail recent Compose logs/server_stats: Start/stop counters and last events/server_uptime_log: Uptime event log/server_historic: Historic uptime summary/debug_monitor: Monitor thread details
Admin-only:
/add <user_id>: Authorize a user (also works by replying to a user message)/remove_user <user_id>: Revoke a user/list_users: List authorized users/add_chat <chat_id>: Authorize a group chat (or reply in a group)/remove_chat <chat_id>: Revoke a group chat/list_chats: List authorized chats/broadcast <message>: Broadcast to all users/chats/shutdown_bot: Stop the bot
- Admin: The
ADMIN_IDspecified in.env. Can run all admin commands. - Authorized Users: Can use bot commands in DMs and authorized group chats.
- Authorized Group Chats: Only these group chats can run start/stop commands.
- Chat IDs are negative numbers (e.g.,
-1001234567890). Add via/add_chat.
- Chat IDs are negative numbers (e.g.,
- Create a bot with BotFather and copy the token into
TELEGRAM_TOKEN. - To find your numeric user ID: start the bot, try an admin command, and note the reported ID.
Rebuild server_sessions.json and server_stats.json from server_uptime.log:
make repairThe script prints a summary and anomaly counts.
server_uptime.log: Event logserver_sessions.json: Session list (start, end, duration)server_stats.json: Aggregated counters and last eventsdata/users.json,data/chats.json: Authorized identities*.bakbackups are created on updates for safety
Note: These files and the data/ directory are created automatically when you run the bot. If they are missing, the bot will generate them as needed; no manual setup is required.
bot.py: Telegram bot entry point (concise)minecraft.py: Server manager (start/stop/monitor, stats and sessions)access.py: Persistence and broadcast for users/chats underdata/scripts/repair_history.py: Rebuild sessions/stats fromserver_uptime.logMakefile:venv,install,all,style, andrepairtargetsrequirements.txt: Runtime dependenciesrequirements-dev.txt: Dev tooling (e.g.,ruff).env.example: Example configuration; copy to.envRELEASE_NOTES.md: Version highlights (e.g., v1.0.0).github/workflows/ci.yml: CI to run install and lint on pushes/PRsscreenshots/: repository images used in READMEstart.pngserver_start_status_stop.pngserver_uptime_log.pngserver_historic.pnghelp.png
server_uptime.log,server_sessions.json,server_stats.json: Runtime historydata/: runtime data (users.json,chats.json, backups)
.gitignore: Ignore local-only files (e.g.,.env, venv,__pycache__, runtime JSON/logs)README.md: This documentation and usage guideLICENSE: License text
The code in this repository is licensed under the Apache License 2.0 (Apache-2.0). You may use, modify, and distribute the software for any purpose, including commercial use, provided you retain copyright and license notices and include a NOTICE file where applicable. The license includes a patent grant with termination if a contributor initiates patent litigation.
See LICENSE for the full text.




