Path: blob/master/examples/multiple_from_file.js
9427 views
/*1* This example is for people with multiple (mojang) minecraft accounts,2* in a file in the format "username:password" on each line,3* change the file property of config to set your .txt file location4*/56const fs = require('fs')7const util = require('util')8const mineflayer = require('mineflayer')9const readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8')1011const config = {12host: 'localhost',13port: 25565,14file: './accounts.txt',15interval: 500 // cooldown between joining server too prevent joining too quickly16}1718function makeBot ([_u, _p], ix) {19return new Promise((resolve, reject) => {20setTimeout(() => {21const bot = mineflayer.createBot({22username: _u,23password: _p,24host: config.host,25port: config.port26})27bot.on('spawn', () => resolve(bot))28bot.on('error', (err) => reject(err))29setTimeout(() => reject(Error('Took too long to spawn.')), 5000) // 5 sec30}, config.interval * ix)31})32}3334async function main () {35// convert accounts.txt => array36const file = await readFile(config.file)37const accounts = file.split(/\r?\n/).map(login => login.split(':'))38const botProms = accounts.map(makeBot)39// const bots = await Promise.allSettled(botProms)40const bots = (await Promise.allSettled(botProms)).map(({ value, reason }) => value || reason).filter(value => !(value instanceof Error))41console.log(`Bots (${bots.length} / ${accounts.length}) successfully logged in.`)42}4344main()454647