All articles
minecraftJanuary 8, 2026ยท5 min read

Mineflayer Minecraft Bot Hosting - Complete Guide

Learn how to create and host Minecraft bots using Mineflayer on ModVC. Automate farming, building, and more with this step-by-step tutorial.

Mineflayer Minecraft Bot Hosting Guide

Create powerful Minecraft bots using Mineflayer and host them 24/7 for free on ModVC. This guide covers everything from basic setup to advanced automation.

What is Mineflayer?

Mineflayer is a JavaScript library that lets you create Minecraft bots. These bots can:

  • Farm crops automatically
  • Mine resources
  • Build structures
  • Chat with players
  • Perform complex tasks

Part 1: Setting Up Your Bot

Prerequisites

  • Basic JavaScript knowledge
  • Node.js installed locally
  • A Minecraft server to connect to

Install Dependencies

mkdir minecraft-bot
cd minecraft-bot
npm init -y
npm install mineflayer

Basic Bot Structure

Create index.js:

const mineflayer = require('mineflayer');

// Create the bot
const bot = mineflayer.createBot({
    host: process.env.MC_HOST || 'localhost',
    port: parseInt(process.env.MC_PORT) || 25565,
    username: process.env.MC_USERNAME || 'ModVCBot',
    // For online-mode servers:
    // auth: 'microsoft'
});

// Bot spawned in world
bot.once('spawn', () => {
    console.log('โœ… Bot has spawned!');
    console.log(`๐Ÿ“ Position: ${bot.entity.position}`);
    bot.chat('Hello! I am a ModVC bot!');
});

// Listen for chat messages
bot.on('chat', (username, message) => {
    if (username === bot.username) return;
    
    console.log(`[${username}] ${message}`);
    
    // Respond to commands
    if (message === '!come') {
        const player = bot.players[username];
        if (player) {
            bot.chat(`Coming to you, ${username}!`);
            bot.pathfinder.goto(player.entity.position);
        }
    }
});

// Handle errors
bot.on('error', console.error);
bot.on('kicked', reason => console.log('Kicked:', reason));

Part 2: Adding Pathfinding

Install Pathfinder Plugin

npm install mineflayer-pathfinder

Enable Pathfinding

const { pathfinder, Movements, goals } = require('mineflayer-pathfinder');

bot.once('spawn', () => {
    // Load pathfinder
    bot.loadPlugin(pathfinder);
    
    // Set movement options
    const movements = new Movements(bot);
    bot.pathfinder.setMovements(movements);
});

// Command to follow a player
bot.on('chat', (username, message) => {
    if (message === '!follow') {
        const player = bot.players[username]?.entity;
        if (player) {
            const goal = new goals.GoalFollow(player, 2);
            bot.pathfinder.setGoal(goal, true);
            bot.chat('Following you!');
        }
    }
    
    if (message === '!stop') {
        bot.pathfinder.setGoal(null);
        bot.chat('Stopped following.');
    }
});

Part 3: Auto-Farming Bot

Complete Wheat Farming Bot

const mineflayer = require('mineflayer');
const { pathfinder, goals } = require('mineflayer-pathfinder');

const bot = mineflayer.createBot({
    host: process.env.MC_HOST,
    port: parseInt(process.env.MC_PORT) || 25565,
    username: process.env.MC_USERNAME || 'FarmBot'
});

bot.loadPlugin(pathfinder);

// Find and harvest wheat
async function harvestWheat() {
    const wheat = bot.findBlock({
        matching: block => block.name === 'wheat' && block.metadata === 7,
        maxDistance: 32
    });
    
    if (wheat) {
        await bot.pathfinder.goto(new goals.GoalBlock(wheat.position.x, wheat.position.y, wheat.position.z));
        await bot.dig(wheat);
        console.log('Harvested wheat at', wheat.position);
        
        // Plant new seed
        const seeds = bot.inventory.findInventoryItem('wheat_seeds');
        if (seeds) {
            await bot.equip(seeds, 'hand');
            await bot.placeBlock(wheat, new Vec3(0, 1, 0));
        }
        
        // Continue farming
        setTimeout(harvestWheat, 500);
    } else {
        // No wheat ready, wait and check again
        setTimeout(harvestWheat, 5000);
    }
}

bot.once('spawn', () => {
    console.log('Farm bot ready!');
    bot.chat('Starting auto-farm...');
    harvestWheat();
});

Part 4: Deploying to ModVC

1. Package Your Bot

Your package.json:

{
  "name": "minecraft-bot",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "mineflayer": "^4.14.0",
    "mineflayer-pathfinder": "^2.4.5"
  }
}

2. Create ZIP and Upload

  1. Zip your project folder
  2. Upload to ModVC Dashboard
  3. Set environment variables:
    • MC_HOST = your.server.ip
    • MC_PORT = 25565
    • MC_USERNAME = BotName

3. Start the Bot

Click Start and watch your bot connect!


Advanced Features

PvP Combat Bot

const { PVP } = require('mineflayer-pvp');

bot.loadPlugin(PVP);

bot.on('chat', (username, message) => {
    if (message === '!attack') {
        const target = bot.players[username]?.entity;
        if (target) {
            bot.pvp.attack(target);
        }
    }
});

Anti-AFK

// Prevent being kicked for inactivity
setInterval(() => {
    bot.setControlState('jump', true);
    setTimeout(() => bot.setControlState('jump', false), 100);
}, 30000);

Troubleshooting

"Failed to connect"

  • Check host and port are correct
  • Verify server is online
  • Try using IP instead of domain

"Invalid session"

  • For online-mode, you need Microsoft auth
  • Use offline-mode servers for testing

Bot disconnects randomly

  • Add auto-reconnect logic
  • Check server whitelist settings

Your Minecraft bot is now running 24/7 on ModVC! ๐ŸŽฎ