mcafk icon

mcafk

Verified

by adbro

Afk bot for minecraft.

Download v1.0.0
1 downloads

About this Bot

Minecraft AFK Bot

Production-grade, resilient headless Minecraft automation bot built with Node.js and Mineflayer. Keeps chunks loaded, maintains player quotas, runs afk farms, and prevents idle kick timeouts with randomized behavioral routines, an embedded real-time web monitoring dashboard, and Discord webhook notifications.

Table of Contents

  • Overview
  • Features
  • Architecture
  • Getting Started
- Prerequisites - Local Setup - Cloud Hosting Setup
  • Environment Variables
  • Chat Commands
  • Web Dashboard Guide
  • Server Compatibility
  • Troubleshooting FAQ
  • License
---

Overview

Minecraft AFK Bot is an automated client designed for Minecraft server environments ranging from private survival multiplayer (SMP) instances to large public networks. Unlike simple macro clickers or static clients that trigger automated anti-cheat or anti-AFK detection filters, this bot executes organic, randomized behavioral cycles including camera yaw/pitch shifts, short jumps, discrete sneaking, arm swings, and micro-positioning adjustments.

The application includes an internal Express web server providing a browser-based monitoring dashboard, real-time telemetry endpoints, and automated health checks designed for cloud platform keep-alive pings.

---

Features

  • Natural Anti-AFK Simulation: Human-like randomized head rotation, pitch adjustments, discrete jump impulses, sneak states, right-hand arm swings, and micro-step recovery routines with configurable jittered intervals (default 15 to 45 seconds).
  • Resilient Auto-Reconnection: Exponential backoff with random jitter (+/- 20%) to safely recover from server restarts, connection drops, network timeouts, and sudden proxy kicks.
  • Autonomous Survival Mechanics: Automated eating when hunger drops below 15 points (detecting 18+ vanilla Minecraft food types from inventory) and instantaneous auto-respawn upon player death.
  • In-Game Chat Control: In-game command execution via customizable prefix (e.g., !status, !coords, !antiafk, !jump, !eat, !say).
  • Real-Time Web Monitoring Dashboard: Express-powered web UI running on configurable port (default 3000) with live health, hunger, coordinates, latency, uptime, and recent activity logs.
  • External Uptime Monitoring Support: Built-in /health JSON endpoint responding with HTTP 200/503 for UptimeRobot, BetterStack, or cron pings.
  • Discord Webhook Alerting: Automated rich embed alerts for bot connection, world spawn, death, kicks, and low health.
  • Multi-Mode Authentication & Protocol Support: Seamless support for offline/cracked servers and official Microsoft authentication, with auto-version negotiation or explicit version locking from Minecraft 1.8.x through 1.20.x+.
---

Architecture

minecraft-afk-bot/
├── assets/
│   └── icon.svg              # Pixelated bot avatar and brand icon
├── src/
│   ├── antiAfk.js            # Randomized anti-AFK behavioral manager
│   ├── bot.js                # Core Mineflayer client and event coordinator
│   ├── config.js             # Environment variable validation and defaults
│   ├── index.js              # Application bootstrapper and signal handler
│   └── webDashboard.js       # Express HTTP status dashboard and health API
├── env.example.txt           # Configuration template
├── package.json              # Node.js project manifest and dependencies
├── LICENSE.txt               # MIT License
└── README.md                 # Project documentation

---

Getting Started

Prerequisites

Ensure the following runtimes are installed on your system:

  • Node.js: version 18.0.0 or higher
  • npm: version 9.0.0 or higher
  • Network access to target Minecraft server (IP address and port)
Verify your Node.js and npm installations:

node -v
npm -v

Local Setup

1. Clone or extract the repository into your desired directory:

cd minecraft-afk-bot

2. Install dependencies:

npm install

3. Create your local environment configuration file:

cp env.example.txt .env

On Windows PowerShell:

Copy-Item env.example.txt .env

4. Open .env in a text editor and adjust your Minecraft server connection settings:

MC_HOST=mc.yourserver.com
MC_PORT=25565
MC_USERNAME=AFK_Bot
MC_AUTH=offline

5. Launch the application:

npm start

Or run directly with Node:

node src/index.js

6. Access the web dashboard by opening http://localhost:3000 in any web browser.

---

Cloud Hosting Setup

The bot can be deployed 24/7 on major cloud application platforms such as Render, Railway, Fly.io, Heroku, or custom Linux virtual private servers (VPS).

#### Cloud Build and Start Specifications

  • Build Command: npm install --production
  • Start Command: node src/index.js
  • Exposed Port: Configure the environment variable PORT according to your platform (typically 3000 or dynamically assigned).
#### Example: Deploying on Render (Web Service)

1. Connect your repository to Render.
2. Select Environment: Node.
3. Set the Build Command to:

npm install --production

4. Set the Start Command to:
node src/index.js

5. In the Environment Variables section, add your configuration keys (e.g., MC_HOST, MC_PORT, MC_USERNAME, MC_AUTH).
6. Set up a free external uptime monitor (such as UptimeRobot or Cron-Job.org) pointing to https://your-service.onrender.com/health with a 5-minute interval. This keeps the free-tier service alive without spinning down.

#### Example: Deploying on Linux VPS (Ubuntu / Debian with PM2)

1. Install PM2 process manager globally:

npm install -g pm2

2. Navigate to the project root:
cd /opt/minecraft-afk-bot
npm install --production

3. Start the process with PM2:
pm2 start src/index.js --name "minecraft-afk-bot"

4. Enable startup persistence across system reboots:
pm2 startup
pm2 save

---

Environment Variables

All settings can be configured via environment variables or a local .env file. Below is the complete specification:

| Variable | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| MC_HOST | String | localhost | Hostname or IP address of the target Minecraft server. |
| MC_PORT | Integer | 25565 | Target Minecraft server port. |
| MC_USERNAME | String | AFK_Bot | In-game player username or Microsoft account email. |
| MC_VERSION | String | (auto-detect) | Target Minecraft version (e.g., 1.20.4, 1.19.2). Leave blank for auto negotiation. |
| MC_AUTH | String | offline | Authentication mode: offline (cracked/LAN) or microsoft (official Mojang account). |
| MC_PASSWORD | String | (empty) | Optional password (used for custom server setups or auth plugins). |
| PORT | Integer | 3000 | HTTP port for the web dashboard and health check endpoint. |
| HOST | String | 0.0.0.0 | Network binding interface for the HTTP web server. |
| WEB_DASHBOARD_ENABLED | Boolean | true | Toggle the built-in HTTP status monitor web server (true or false). |
| DISCORD_WEBHOOK_URL | String | (empty) | Discord webhook URL for automated status and alert embed notifications. |
| ANTI_AFK_ENABLED | Boolean | true | Master toggle for the anti-AFK behavioral loop (true or false). |
| ANTI_AFK_MIN_DELAY_MS | Integer | 15000 | Minimum interval between anti-AFK actions in milliseconds (15 seconds). |
| ANTI_AFK_MAX_DELAY_MS | Integer | 45000 | Maximum interval between anti-AFK actions in milliseconds (45 seconds). |
| AUTO_RESPAWN | Boolean | true | Automatically respawn after death (true or false). |
| AUTO_EAT | Boolean | true | Automatically detect and consume food when hunger falls below 15 (true or false). |
| CHAT_PREFIX | String | ! | Prefix required for in-game chat commands sent to the bot. |
| RECONNECT_MIN_INTERVAL_MS| Integer | 5000 | Initial reconnection delay in milliseconds (5 seconds). |
| RECONNECT_MAX_INTERVAL_MS| Integer | 60000 | Upper limit for exponential reconnection backoff in milliseconds (60 seconds). |

---

Chat Commands

Players in the same server can send commands to the bot via in-game chat. All commands use the prefix defined in CHAT_PREFIX (default: !).

| Command | Arguments | Description | Example Usage |
| :--- | :--- | :--- | :--- |
| !status | None | Displays current health points, hunger bar, and 3D world coordinates. | !status |
| !coords | None | Prints the exact X, Y, and Z position of the bot in chat. | !coords |
| !jump | None | Forces the bot to execute a single vertical jump. | !jump |
| !eat | None | Triggers an immediate search of inventory for food and consumes it. | !eat |
| !antiafk | [on\|off] | Queries current status or enables/disables the anti-AFK behavioral loop. | !antiafk off |
| !say | <message> | Echoes the specified message directly into the server chat. | !say Farm active |
| !help | None | Prints a list of available chat commands and usage syntax. | !help |

---

Web Dashboard Guide

When WEB_DASHBOARD_ENABLED=true, the bot hosts an integrated status interface accessible via standard web browsers.

Interface Overview

1. Real-Time Status Header:
- Visual status badge reflecting current connection state (Connected, Spawning, Connecting, or Disconnected).
- Server address and active in-game username.
2. Metrics Cards:
- Coordinates: Real-time X, Y, Z coordinates with 1-decimal precision.
- Health Bar: Current health out of 20 points with colorized indicator.
- Hunger Bar: Current food level out of 20 points.
- Server Latency: Dynamic ping measured in milliseconds.
- Process Uptime: Duration since application boot in hours, minutes, and seconds.
3. Anti-AFK Telemetry:
- Behavioral routine state (Active or Paused).
- Last action executed (look, jump, sneak, swing, or micro_step).
- Timestamp and elapsed seconds since the last action.
4. Live Activity Log:
- Real-time rolling feed displaying the last 50 bot events, chat commands, and connection logs.

API Endpoints

The dashboard exposes lightweight REST endpoints suitable for programmatic integrations and uptime monitors:

  • GET /health
- Returns HTTP 200 when connected or spawning; HTTP 503 when disconnected or uninitialized. - Response format:
{
      "status": "healthy",
      "botState": "connected",
      "uptimeSeconds": 1420,
      "timestamp": "2026-11-16T10:00:00.000Z"
    }
  • GET /api/status
- Returns complete telemetry payload including coordinates, health, food level, ping, logs, and anti-AFK state.
  • GET /
- Serves the standalone responsive HTML dashboard interface.

---

Server Compatibility

Minecraft AFK Bot is built on standard Minecraft protocol implementations and has been tested across a broad range of server software and hosting providers.

Authentication Compatibility

  • Offline / Cracked Servers:
- Set MC_AUTH=offline. - Works with any server running online-mode=false. - Compatible with login security plugins (such as AuthMe or LoginSecurity) via the !say /login <password> command or automated chat triggers.
  • Microsoft / Online Servers:
- Set MC_AUTH=microsoft. - Supports official Mojang/Microsoft authenticated accounts. - On first boot, Mineflayer will output a device code URL to the terminal console. Open the link in a browser, enter the code, and sign in. Tokens are securely cached locally for subsequent seamless connections.

Server Software Compatibility

  • Vanilla Minecraft: Version 1.8 through 1.20.x+.
  • PaperMC, Purpur, Tuinity: Fully supported.
  • Spigot, CraftBukkit: Fully supported.
  • Fabric & Quilt: Fully supported (client connects over standard vanilla protocol).
  • Forge: Supported on servers that accept vanilla client connections.

Hosting Platform Compatibility

  • Aternos: Fully supported. For offline mode, ensure cracked mode is enabled in your Aternos server options. Provide the dynip or hostname and mapped port.
  • Minehut: Fully supported. Connect directly using yourserver.minehut.gg or direct IP.
  • Dedicated Hosts: Shockbyte, Apex Hosting, PebbleHost, BisectHosting, Scalacube, and private VPS hosts.
---

Troubleshooting FAQ

The bot connects but gets kicked immediately with "Kicked for flying" or "Illegal movement"

Many servers enable strict movement checks. In server.properties, ensure allow-flight=true is set if you are the server administrator. If playing on a public server, the bot's micro_step action or jump routine may be conflicting with anti-cheat plugins (e.g., NoCheatPlus or GrimAC). You can increase ANTI_AFK_MIN_DELAY_MS to 30000 (30 seconds) in .env to make movements less frequent.

The bot fails to connect with "ECONNREFUSED" or "ETIMEDOUT"

Verify that the server IP address (MC_HOST) and port (MC_PORT) are correct. If using an SRV domain (e.g., play.example.com), make sure your DNS resolution is functioning properly. If your server is hosted on Aternos, remember that Aternos servers use dynamic ports that change each time the server starts up.

The bot is not eating food automatically

Ensure that the bot has edible items in its inventory (e.g., cooked beef, bread, baked potato, cooked porkchop). The auto-eat routine activates when food level falls below 15. The bot must not be under active attack or continuously moving when consuming food.

Microsoft authentication asks for a code on every reboot

Mineflayer caches authentication tokens in a temporary credentials directory. Ensure the bot process has read and write permissions to the filesystem. When running in containerized environments (such as Docker or ephemeral cloud dynos), mount a persistent volume for the application directory so token cache files are preserved.

The web dashboard port is already in use (EADDRINUSE)

Another process on your host is utilizing port 3000. Specify an alternative port by modifying PORT=3001 or any available port in your .env file.

How do I prevent the bot from being targeted by hostile mobs?

Position the bot inside a secure, fully enclosed room with illumination level 8 or higher to prevent mob spawns. Placing the bot inside a fenced enclosure or glass observation booth ensures it remains safe from creepers and phantoms while keeping local mob and crop farms active.

---

License

This project is licensed under the MIT License. See the LICENSE.txt file for full license terms.

Package Versions (1)

Version Channel Runtime Size Action
1.0.0 release Node.js 22 LTS 0.02 MB Download

Changelog

[Node.js 22 LTS] 1.0.0 11/16/2026

New: Minecraft AFK Bot

  • Added human-like randomized movements and anti-AFK features.
  • Added automatic reconnect and respawn.
  • Added auto-eating to maintain hunger.
  • Added web dashboard with live bot stats and health API.
  • Added in-game commands (!status, !coords, !jump, !eat, !antiafk, !say).
  • Added optional Discord webhook alerts.
  • Added support for Minecraft Java 1.8.x–1.21.x and Microsoft/Offline authentication.

Project Details

Runtime Other
Category Minecraft bot
License MIT
Published 11/16/2026
Last Updated 11/16/2026

Author

adbro avatar
adbro Owner