Your First Script
Simple Chat Command
Create a script that responds to chat commands.
Script: chat_commands.py
import bot
import baritone
import utils
@on("chat_message")
def handle_commands(sender, message, msg_type):
if message == "!pos":
pos = bot.position()
bot.chat(f"Position: {pos['x']:.1f}, {pos['y']:.1f}, {pos['z']:.1f}")
elif message == "!goto spawn":
baritone.goto(0, 64, 0)
bot.chat("Going to spawn!")
elif message == "!stop":
baritone.cancel()
bot.chat("Stopped")
How it Works
@on("chat_message")- Registers handler for chat messageshandle_commands(sender, message, msg_type)- Function called when chat received- Checks message content and responds accordingly
Running
- Save the script
- Enable it in the Scripts tab
- Click Run to start the script
- Type
!pos,!goto spawn, or!stopin-game
Debugging
Use utils.log() to debug:
@on("chat_message")
def handle_commands(sender, message, msg_type):
utils.log(f"Received: {message} from {sender}")
if message == "!pos":
# ...
Logs appear in the bots console tab.