Mineflayer
Create Minecraft bots with a powerful, stable, and high level JavaScript API.
Install / Use
/learn @PrismarineJS/MineflayerREADME
Mineflayer
| <sub>EN</sub> English | <sub>RU</sub> русский | <sub>ES</sub> Español | <sub>FR</sub> Français | <sub>TR</sub> Türkçe | <sub>ZH</sub> 中文 | <sub>BR</sub> Português | |-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|-------------------------|--------------------|
Create Minecraft bots with a powerful, stable, and high level JavaScript API, also usable from Python.
First time using Node.js? You may want to start with the tutorial. Know Python? Checkout some Python examples and try out Mineflayer on Google Colab.
Features
- Supports Minecraft 1.8 to 1.21.11 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.20, 1.21, 1.21.9, 1.21.11) <!--version-->
- Entity knowledge and tracking.
- Block knowledge. You can query the world around you. Milliseconds to find any block.
- Physics and movement - handle all bounding boxes
- Attacking entities and using vehicles.
- Inventory management.
- Crafting, chests, dispensers, enchantment tables.
- Digging and building.
- Miscellaneous stuff such as knowing your health and whether it is raining.
- Activating blocks and using items.
- Chat.
Roadmap
Checkout this page to see what our current projects are.
Installation
First install Node.js >= 18 from nodejs.org then:
npm install mineflayer
To update mineflayer (or any Node.js) package and its dependencies, use
npm update
Documentation
| link | description | |---|---| |tutorial | Begin with Node.js and mineflayer | | FAQ.md | Got a question ? go there first | | api.md <br/>unstable_api.md | The full API reference | | history.md | The changelog for mineflayer | | examples/ | Checkout all the mineflayer examples |
Contribute
Please read CONTRIBUTING.md and prismarine-contribute
Usage
Videos
A tutorial video explaining the basic set up process for a bot can be found here.
If you want to learn more, more video tutorials are there, and the corresponding source codes for those bots is there.
<img src="https://img.youtube.com/vi/ltWosy4Z0Kw/0.jpg" alt="tutorial 1" width="200"> <img src="https://img.youtube.com/vi/UWGSf08wQSc/0.jpg" alt="tutorial 2" width="200"> <img src="https://img.youtube.com/vi/ssWE0kXDGJE/0.jpg" alt="tutorial 3" width="200"> <img src="https://img.youtube.com/vi/walbRk20KYU/0.jpg" alt="tutorial 4" width="200">
Getting Started
Without a version specified, the version of the server will be guessed automatically. Without auth specified, the mojang auth style will be guessed.
Echo Example
const mineflayer = require('mineflayer')
const bot = mineflayer.createBot({
host: 'localhost', // minecraft server ip
username: 'Bot', // username to join as if auth is `offline`, else a unique identifier for this account. Switch if you want to change accounts
auth: 'microsoft' // for offline mode servers, you can set this to 'offline'
// port: 25565, // set if you need a port that isn't 25565
// version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
// password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
})
bot.on('chat', (username, message) => {
if (username === bot.username) return
bot.chat(message)
})
// Log errors and kick reasons:
bot.on('kicked', console.log)
bot.on('error', console.log)
If auth is set to microsoft, you will be prompted to login to microsoft.com with a code in your browser. After signing in on your browser,
the bot will automatically obtain and cache authentication tokens (under your specified username) so you don't have to sign-in again.
To switch the account, update the supplied username. By default, cached tokens will be stored in your user's .minecraft folder, or if profilesFolder is specified, they'll instead be stored there.
For more information on bot options see node-minecraft-protocol's API doc.
Connecting to a Realm
To join a Realm that your Minecraft account has been invited to, you can pass a realms object with a selector function like below.
const client = mineflayer.createBot({
username: 'email@example.com', // minecraft username
realms: {
// This function is called with an array of Realms the account can join. It should return the one it wants to join.
pickRealm: (realms) => realms[0]
},
auth: 'microsoft'
})
See what your bot is doing
Thanks to the prismarine-viewer project, it's possible to display in a browser window what your bot is doing.
Just run npm install prismarine-viewer and add this to your bot:
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
bot.once('spawn', () => {
mineflayerViewer(bot, { port: 3007, firstPerson: true }) // port is the minecraft server port, if first person is false, you get a bird's-eye view
})
And you'll get a live view looking like this:
More Examples
| example | description | |---|---| |viewer | Display your bot world view in the browser | |pathfinder | Make your bot go to any location automatically | |chest | Use chests, furnaces, dispensers, enchantment tables | |digger | Learn how to create a simple bot that is capable of digging blocks | |discord | Connect a discord bot with a mineflayer bot | |jumper | Learn how to move, jump, ride vehicles, attack nearby entities | |ansi | Display your bot's chat with all of the chat colors shown in your terminal | |guard | Make a bot guard a defined area from nearby mobs | |multiple-from-file | Add a text file with accounts and have them all login |
And many more in the examples folder.
Modules
A lot of the active development is happening inside of small npm packages which are used by mineflayer.
The Node Way™
"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons." — substack from "how I write modules"
Modules
These are the main modules that make up mineflayer:
| module | description | |---|---| | minecraft-protocol | Parse and serialize minecraft packets, plus authentication and encryption. | minecraft-data | Language independent module providing minecraft data for minecraft clients, servers and libraries. | prismarine-physics | Provide the physics engine for minecraft
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
