A bidirectional chat interface between Python and Minecraft Bedrock Edition dedicated servers using Go with gophertunnel.
GopherSnake MC provides a bridge between Python applications and Minecraft Bedrock Edition's chat system. It consists of:
- A Go server that connects to Minecraft using gophertunnel
- A Python client library for easy integration with Python applications
This allows you to:
- Send chat messages to Minecraft from Python
- Receive chat messages from Minecraft in Python
- Create chatbots, automation tools, or external interfaces to Minecraft
- Python 3.6+
- websocket-client
- For authentication: msal and requests
GopherSnake MC uses the Microsoft Xbox Live authentication system for online mode. This requires:
- A valid Microsoft account with Minecraft purchased
- Python with the required packages installed:
pip install msal requests
The authentication flow uses Microsoft Authentication Library (MSAL) to:
- Authenticate with Microsoft Account using a device code flow
- Exchange the Microsoft token for Xbox Live credentials
- Get XSTS tokens necessary for Minecraft authentication
- Cache tokens securely to avoid frequent re-authentication
You'll be prompted to visit a Microsoft URL and enter a code when authentication is needed. Token caching ensures you won't need to do this every time you run the application.
If you encounter authentication issues:
-
Missing Python packages: Ensure you've installed the required packages:
pip install msal requests
-
Token not being accepted: Clear the cache by deleting the
xbl3_token_cache.bin
file (location will be shown in logs) -
Authentication flow fails: Ensure you're completing the Microsoft login process within the time window (usually 15 minutes)
-
Python not found: Make sure Python is installed and in your PATH. The application tries to detect Python using different names (py, python, python3)
-
Clone the repository:
git clone https://github.com/DJStompZone/gophersnake_mc.git cd gophersnake_mc
-
Install Go dependencies:
go mod download
-
Install Python dependencies:
pip install websocket-client msal requests
Edit config.json
to match your setup:
go run .
Or build and run the executable:
go build
./gophersnake_mc
from minecraft_chat import MinecraftChatClient
# Create a new client
client = MinecraftChatClient("ws://localhost:8080/chat")
# Register a callback for incoming chat messages
def on_chat_message(sender, message):
print(f"[{sender}] {message}")
# Auto-reply to messages containing "hello"
if "hello" in message.lower():
client.send_chat_message(f"Hello {sender}!")
client.register_chat_callback(on_chat_message)
# Connect to the server
client.connect()
# Send a message to all players
client.send_chat_message("Hello from Python!")
-
Connection refused to Minecraft server
- Ensure your Bedrock server is running and accessible
- Check that the port in config.json matches your server's port
- Try using the server's IP address instead of localhost
-
Messages not being sent/received
- For dedicated servers, you may need to adjust permissions to allow chat commands
- Check the server logs for any errors related to the connection
- Try restarting both the Go server and the Minecraft server
-
Authentication errors
- For online-mode servers, you'll need to set up proper authentication
- Make sure you've installed the required Python packages:
pip install msal requests
- If problems persist, see the Authentication Troubleshooting section in this README
gophersnake_mc/
├── main.go # Main program entry point
├── chat_server.go # Minecraft chat handling
├── client_manager.go # WebSocket client management
├── config.go # Configuration handling
├── imports.go # Shared imports
├── config.json # Configuration file
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── minecraft_chat.py # Python client library
└── examples/
└── chat_example.py # Example Python chat client
MIT License - See LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.