Automatically monitors and purchases seeds and eggs in the Magic Garden Discord game.
- OCR-based detection - Finds items by reading text (no fragile image templates)
- Smart shop navigation - Teleports to shop, scrolls through all pages (up to 40), loops continuously
- Green button detection - Uses color detection to find buy buttons reliably
- Fuzzy text matching - Handles OCR errors like "arrot" → "Carrot"
- Stock verification - Only clicks items that show "STOCK" (ignores popups)
- Popup dismissal - Automatically closes game popups that block the shop
- Configurable targets - Choose which seeds/eggs to buy
- Shop mode selection - Scan seed shop, egg shop, or both
- Cross-platform - Works on macOS, Windows, and Linux
- GUI and headless modes - Run with interface or AFK in terminal
- uv (recommended) or Python 3.11+
- Magic Garden game (Discord activity)
- Windows only: Tesseract OCR (see below)
- Windows only: pydirectinput (for game input - installed automatically)
- Linux only: Tesseract OCR (
sudo apt install tesseract-ocr)
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and setup
git clone <your-repo-url>
cd magic-garden
uv sync-
Download the installer from: https://github.com/UB-Mannheim/tesseract/wiki
- Get the latest 64-bit version (e.g.,
tesseract-ocr-w64-setup-5.3.3.exe)
- Get the latest 64-bit version (e.g.,
-
Run the installer:
- Install to default path:
C:\Program Files\Tesseract-OCR - Important: Check "Add to PATH" during installation
- Install to default path:
-
Verify installation:
tesseract --version
-
If Tesseract is not in PATH, you'll need to set it manually. Add this to the top of
main.py:import pytesseract pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
Using uv (recommended):
# Install uv
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Clone and setup
git clone <your-repo-url>
cd magic-garden
uv syncUsing pip:
cd magic-garden
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements-windows.txt# Install Tesseract OCR
sudo apt install tesseract-ocr
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and setup
git clone <your-repo-url>
cd magic-garden
uv syncBefore running, set up your game region and preferences in config.json:
Run the region capture tool:
uv run python main.py --set-regionFollow the prompts to click the top-left and bottom-right corners of your game window.
Edit config.json:
{
"scan_interval": 1.0,
"click_delay": 0.3,
"confidence_threshold": 0.6,
"shop_mode": "seed",
"monitor_region": [799, 479, 882, 766],
"ocr_targets": [
"Mythical Egg",
"Bamboo Seed",
"Sunflower Seed",
"Starweaver Pod",
"Dawnbinder Pod",
"Moonbinder Pod"
],
"use_ocr": true,
"startup_delay": 3
}| Setting | Description | Default |
|---|---|---|
scan_interval |
Seconds between shop cycles | 1.0 |
click_delay |
Delay after each buy click (seconds) | 0.3 |
confidence_threshold |
Template match sensitivity (0-1) | 0.6 |
shop_mode |
Which shops to scan: "seed", "egg", or "both" |
"seed" |
monitor_region |
Game window region [x, y, width, height] |
- |
ocr_targets |
List of item names to buy | - |
use_ocr |
Use OCR text detection (recommended) | true |
startup_delay |
Seconds to wait before starting (focus game) | 3 |
max_buy_attempts |
Max clicks on buy button before giving up | 20 |
The bot uses template images in the templates/ folder for UI element detection:
close_button.png- X button for dismissing popups (required for popup handling)green_buy_button.png- Buy button (optional, color detection is primary)- Various seed/egg templates (legacy, OCR is now preferred)
If templates/close_button.png is missing, the bot falls back to HSV color detection for white X buttons.
uv run python main.py --headlessThe bot will:
- Wait 3 seconds (focus your game window)
- Press Shift+1 to teleport to shop
- Press Space to open seed shop
- Scroll through all pages, buying configured items
- Loop back to step 2
Press Ctrl+C to stop.
uv run python main.pyControls:
- F6: Start/Pause
- F7: Stop
- Mouse to corner: Emergency stop (pyautogui failsafe)
# Set game region interactively
uv run python main.py --set-regionYou can package the bot as a standalone .exe that users can run without installing Python.
-
Install PyInstaller:
pip install pyinstaller
-
Windows: Ensure Tesseract is installed at
C:\Program Files\Tesseract-OCR- The build will automatically bundle Tesseract into the executable
pyinstaller magic-garden.specThe executable will be in the dist/ folder as MagicGardenBot.exe.
- Python runtime
- All dependencies (OpenCV, pytesseract, EasyOCR, PyTorch)
- Tesseract OCR - bundled on all platforms (no separate install needed)
- pydirectinput (Windows only - for game input compatibility)
- Default config and templates
Notes:
- Executable size is large (~500MB+) due to EasyOCR/PyTorch
- First run may be slow as EasyOCR downloads language models
- Users just double-click to run - no Python or Tesseract install required
GitHub Actions automatically builds and publishes multi-platform releases when you push a version tag:
# Tag your commit with a version
git tag v1.0.0
# Push the tag to trigger the build
git push origin v1.0.0This will:
- Build executables for Windows, macOS, and Linux in parallel
- Bundle Tesseract OCR on each platform (no separate install needed)
- Create a GitHub Release with all executables attached
Users can download directly from the Releases page:
MagicGardenBot.exe- WindowsMagicGardenBot-macos- macOSMagicGardenBot-linux- Linux
- Shop Navigation - Teleports to shop (Shift+1), opens seed/egg shop (Space)
- Popup Dismissal - Detects and closes any popups blocking the shop (template + color detection)
- Screen Capture - Captures the game region defined in config
- OCR Detection - Uses pytesseract to read text on screen
- Stock Filter - Only considers items with "STOCK" text on the same line
- Fuzzy Matching - Matches partial text to handle OCR errors (e.g., "amboo" → "Bamboo")
- Click Item - Clicks on the item to open the buy accordion
- Green Button Detection - Finds buy buttons using HSV color matching (filters out premium currency buttons)
- Buy Loop - Clicks buy button repeatedly until it turns grey (sold out)
- Re-scan Page - After buying, re-scans the page for remaining items (handles layout shifts)
- Scroll & Repeat - Scrolls down (max 40 pages), continues until end of shop, then loops
- End Detection - Detects Moonbinder Pod as last item, scrolls extra to ensure full visibility
When debug mode is enabled, the bot saves diagnostic images to the debug/ folder:
debug/screenshot.png- Current screen capturedebug/green_mask.png- HSV color mask showing detected green regionsdebug/buttons_annotated.png- Screenshot with detected buttons highlighteddebug/close_btn_annotated.png- Close button detection with candidates markeddebug/close_btn_mask.png- HSV mask for white close button detection
These help diagnose issues with button detection, popup dismissal, or region setup.
Bot not detecting items:
- Run
--set-regionto recapture game window bounds - Check that
ocr_targetsin config.json matches exact item names - Check debug output for OCR results and matched text
Green buy button not detected:
- Check
debug/green_mask.pngto see what green regions are detected - The button must be wide (aspect ratio > 1.3) to avoid matching seed icons
- Ensure the game region covers the buy button area
Clicking wrong things:
- The bot filters for items with "STOCK" on the same line - popups shouldn't trigger
- If false positives persist, check the debug output for what text is being matched
Tesseract not found (Windows):
- Ensure Tesseract is installed and in PATH
- Or add the path manually in code (see Windows installation above)
macOS permissions:
- Grant accessibility permissions: System Settings > Privacy & Security > Accessibility
- Add Terminal (or your IDE) to the allowed apps
Bot clicking but not buying:
- Check
debug/buttons_annotated.pngto see if button is detected - Increase
click_delayin config.json if clicks are too fast - Ensure the game window is focused and not obstructed
Popups not being dismissed:
- Check
debug/close_btn_annotated.pngto see detected close button candidates - Ensure
templates/close_button.pngexists (for template matching) - Check that the popup X button is within the monitor region
- The bot tries up to 10 popup dismissals per cycle
Bot clicking premium (donut) buttons:
- The bot filters out buttons >200px to the right of the item
- Ensure your monitor region is set correctly with
--set-region
Use at your own risk. Automation may violate the game's terms of service.