How kitaminka/minecraft-server-bot works
Project Type and Purpose
• This is an open-source Discord bot written in Go.
• Its main use case is managing a Minecraft server whitelist & authorization via Discord commands.
File Structure
Top-level directories and files:
• bot/ – low-level Discord session setup (bot.go)
• connection/ – connectors to DB (db.go), Minecraft plugin (mc_commands.go), player info (player.go), and RCON (rcon.go)
• handlers/ – business logic for commands, components, messages, and modals
• main.go – entry point where the bot and handlers are wired up
• commands.json – definition of slash commands
• .env.example – environment variables (Discord token, DB URL, RCON creds)
Extract Key Insights from README
• Integrates with AuthMeReloaded by default (but configurable).
• Requires a database to store whitelist/authorization state.
• Uses Discord slash commands to drive actions.
Main Components
a. External Services
– Discord Gateway (via Discord API)
– Minecraft Server (AuthMeReloaded plugin)
– Database (e.g., MySQL/PostgreSQL)
b. Internal Modules
– Bot module (bot/bot.go): initializes Discord session, registers commands
– Handlers (handlers/*.go): respond to incoming interactions/messages
– Connection layer (connection/*.go):
• db.go – CRUD ops on whitelist table
• rcon.go – send RCON commands to Minecraft server
• mc_commands.go – wrapper to AuthMeReloaded commands
• player.go – abstraction over Minecraft player data
– Configuration & Command Definitions
• commands.json – slash command specs
• .env – secrets and endpoints
Relationships & Data Flow
1. Discord user invokes a slash command →
2. Discord Gateway forwards interaction to Bot module (bot.go) →
3. Bot module calls appropriate handler (handlers/… .go) →
4. Handler may:
• Query/update the Database (via connection/db.go)
• Issue RCON command to Minecraft server (via connection/rcon.go & mc_commands.go)
5. Handler constructs a response → Bot module sends reply back over Discord API
Architectural Patterns & Principles
• Layered architecture:
– Presentation: Discord Gateway & Bot module
– Application: Handlers
– Infrastructure: Connection layer (DB & RCON)
• Single Responsibility: each directory/file has a clear role
• Configuration-driven: commands.json and .env drive runtime behavior
• Modular: easy to swap out AuthMeReloaded for another plugin
Essential Elements
• Component names & roles (e.g., “Handler: /send-whitelist”)
• Configuration files (.env, commands.json) as a separate node