Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mineflayer = require('mineflayer');
- console.log("begin mineflayer js file")
- const bot = mineflayer.createBot()
- console.log("defualt login info used -- bot loging in")
- bot.on('login', () => {
- console.log('Bot connected');
- })
- bot.on('spawn', () => {
- bot.chat("Hello, all!!");
- console.log('bot spawned');
- })
- bot.on("chat", (username, message) => {
- console.log(`chat ${message}`)
- if (username === bot.username) return
- /* if (message = `{Hi|hi|helo|hello|Hello}`) { */
- if (message.match = (/hi |Hi |hello |Hello |hey |Hey |Hay |hay /g)) {
- console.log("chat hi used")
- bot.chat(`Hello ${username} I am an example bot`)
- bot.chat('you can tell me to leave the server')
- bot.chat(' but you have to whisper it the chat bar to me')
- bot.chat(`"/tell ${bot.username} leave"`)
- bot.chat("but the example is when you tell me hi in whisper")
- bot.chat(`"/tell ${bot.username} hi"`)
- bot.chat(`"I think I echo, stutter or something."`)
- }
- })
- bot.on("whisper", (username, message,) => {
- if (username === bot.username) return
- console.log(`whisper ${message}`)
- if (message === "hi") {
- console.log("wisper hi used")
- bot.whisper(username, (`Hello ${username}`))
- bot.whisper(username, ("as you can see I am going to respond in open chat like a parrot"))
- bot.whisper(username, ("I should not do this.... if chat and whisper are seperated"))
- bot.whisper(username, ("thank you"))
- }
- if (message === "leave") {
- quit();
- }
- });
- function lookAtNearestPlayer() {
- const playerFilter = (entity) => entity.type === 'player'
- const playerEntity = bot.nearestEntity(playerFilter)
- if (!playerEntity) return
- const pos = playerEntity.position.offset(0, playerEntity.height, 0)
- bot.lookAt(pos)
- }
- function quit() {
- bot.chat("I got to go now. See you later")
- bot.whisper('username', `Quit command used, I will leave the server now!! ---> count to 5 slowly`);
- console.log('quit command used, and proccess ending');
- setTimeout(() => {
- bot.quit('quitting')
- console.log("ending mineflayer js file and exiting proccess instance")
- }, 5000) /* 1000 = 1 secound */
- setTimeout(() => {
- process.exit(0)
- }, 5000) /* 1000 = 1 secound */
- }
- bot.on('physicTick', lookAtNearestPlayer);
RAW Paste Data