Created
July 4, 2024 22:38
-
-
Save nycki93/a64f79935e81efd28c621e070d95bbf7 to your computer and use it in GitHub Desktop.
mineflayer afk script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { readFileSync } from 'node:fs'; | |
| import { createInterface, moveCursor } from 'node:readline'; | |
| import { createBot } from 'mineflayer'; | |
| const config = JSON.parse(readFileSync('config.json')); | |
| const { host, port, username, password } = config; | |
| const PROMPT = '> '; | |
| const rl = createInterface({ | |
| input: process.stdin, | |
| output: process.stdout, | |
| }); | |
| function write(text) { | |
| moveCursor(process.stdout, -1 * PROMPT.length, 0); | |
| console.log(text); | |
| rl.prompt(); | |
| } | |
| const bot = createBot({ host, port, username, auth: 'offline' }); | |
| console.log('bot created.'); | |
| bot.on('spawn', () => { | |
| bot.chat(`/login ${password}`); | |
| rl.setPrompt(PROMPT); | |
| rl.prompt(); | |
| }); | |
| bot.on('resourcePack', () => { | |
| bot.denyResourcePack(); | |
| }); | |
| bot.on('message', (message) => { | |
| if (!message.unsigned && !message.toString().trim()) return; | |
| let messageStr = message.toAnsi().trim(); | |
| if (message.unsigned) { | |
| const whole = message.unsigned.getText(); | |
| const text = message.getText(); | |
| const user = whole.slice(0, whole.length - text.length); | |
| messageStr = `<${user}> ${messageStr}`; | |
| } | |
| write(messageStr); | |
| }); | |
| rl.on('line', (line) => { | |
| if (line === '/list') { | |
| const players = Object.keys(bot.players); | |
| write(players.join(', ')); | |
| } else { | |
| bot.chat(line.toString()); | |
| } | |
| }); | |
| bot.on('playerJoined', (player) => { | |
| write(`${player.displayName} joined.`); | |
| }); | |
| bot.on('playerLeft', (player) => { | |
| write(`${player.displayName} left.`); | |
| }); | |
| bot.on('error', console.log) | |
| bot.on('kicked', console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment