This Frequently Asked Question document is meant to help people for the most common things.
Make sure the email you entered into the username option in createBot can be used to login to minecraft.net
using the 'Login with Microsoft' button.
Make sure you have the option auth: 'microsoft'
in your createBot options.
When you get an error that says something about invalid credentials or 'Does this account own Minecraft?' try removing the password field in the createBot
options and try again.
Use hideErrors: true
in createBot options
You may also choose to add these listeners :
client.on('error', () => {})
client.on('end', () => {})
Spigot servers, in particular some plugins, use custom chat formats, you need to parse it with a custom regex / parser. Read and adapt chat_parsing.js to make it work for your particular chat plugin. Also read http://mineflayer.prismarine.js.org/#/tutorial?id=custom-chat
Most custom minecraft servers have plugin support, and a lot of these plugins say something in chat when something happens. If it is just one message, it's best to use the solution discussed in the solution above, but when these messages are split into many small messages, another option is using the "messagestr"
event as it allows for easily parsing multi-line messages.
Example:
chat message in chat looks like:
(!) U9G has won the /jackpot and received
$26,418,402,450! They purchased 2,350,000 (76.32%) ticket(s) out of the
3,079,185 ticket(s) sold!
const regex = {
first: /\(!\) (.+) has won the \/jackpot and received +/,
second: /\$(.+)! They purchased (.+) \((.+)%\) ticket\(s\) out of the /,
third: /(.+) ticket\(s\) sold!/
}
let jackpot = {}
bot.on('messagestr', msg => {
if (regex.first.test(msg)) {
const username = msg.match(regex.first)[1]
jackpot.username = username
} else if (regex.second.test(msg)) {
const [, moneyWon, boughtTickets, winPercent] = msg.match(regex.second)
jackpot.moneyWon = parseInt(moneyWon.replace(/,/g, ''))
jackpot.boughtTickets = parseInt(boughtTickets.replace(/,/g, ''))
jackpot.winPercent = parseFloat(winPercent)
} else if (regex.third.test(msg)) {
const totalTickets = msg.match(regex.third)[1]
jackpot.totalTickets = parseInt(totalTickets.replace(/,/g, ''))
onDone(jackpot)
jackpot = {}
}
})
By using bot.chat()
.
Example:
bot.chat('/give @p diamond')
Is it possible to login multiple accounts using bot = mineflayer.createbot while controlling them all separately ?
Create different bot instances by calling createBot then do different things for each, see multiple.js
bot.inventory.items() returns an array of the bot's items. You can use a recursive function to loop through them and drop every item using bot.toss(). Click here to see an example
Enabled debug mode https://github.com/PrismarineJS/mineflayer#debug
One way is to increase the checkTimeoutInterval option (to set in createBot) to an higher value (for example 300*1000
which is 5min instead of the default 30s). If you still get disconnected, you can auto reconnect using something like this example https://github.com/PrismarineJS/mineflayer/blob/master/examples/reconnector.js
You can use the item.nbt
property. It is also recommended to use the prismarine-nbt
library. The nbt.simplify()
method may be useful.
Example:
function getLore (item) {
let message = ''
if (item.nbt == null) return message
const nbt = require('prismarine-nbt')
const ChatMessage = require('prismarine-chat')(bot.version)
const data = nbt.simplify(item.nbt)
const display = data.display
if (display == null) return message
const lore = display.Lore
if (lore == null) return message
for (const line of lore) {
message += new ChatMessage(line).toString()
message += '\n'
}
return message
}
You can use a library like repl
to read the console input and use bot.chat()
to send it. You can find an example here.
In the inject()
function for your plugin, you can safely call bot.loadPlugin(anotherPlugin)
to make sure that plugin is loaded. If the plugin was already loaded before, nothing happens.
Note that the order in which plugins are loaded is dynamic, so you should never call another plugin in your inject()
function.
In the options object for mineflayer.createBot(options)
, remove your host
option from the options object, have the following variables declared PROXY_IP, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD, MC_SERVER_ADDRESS, MC_SERVER_PORT
and add this to your options object:
connect: (client) => {
socks.createConnection({
proxy: {
host: PROXY_IP,
port: PROXY_PORT,
type: 5,
userId: PROXY_USERNAME,
password: PROXY_PASSWORD
},
command: 'connect',
destination: {
host: MC_SERVER_ADDRESS,
port: MC_SERVER_PORT
}
}, (err, info) => {
if (err) {
console.log(err)
return
}
client.setSocket(info.socket)
client.emit('connect')
})
}
socks
is declared with const socks = require('socks').SocksClient
and uses this package.
Some servers might reject the connection. If that happens try adding fakeHost: MC_SERVER_ADDRESS
to your createBot options.
This is what happens when either you gave mineflayer the wrong server version, or mineflayer detects the wrong server version
You may be trying to use something on the bot object that isn't there yet, try calling the statement after the spawn
event
Update your node version.
Check that spawn protection isn't stopping the bot from it's action