Categories > Coding > Javascript >

[REL] Minecraft botting couldn't be easier with Mineflayer


New Reply

Aja

Zenexya#2964

Posts: 1125

Threads: 126

Joined: Apr, 2021

Reputation: 0

  • 1

Posted

Hi!
Probably most of you knew that already, but here I come back after a while with a tutorial on how to make a Minecraft bot. You can make it chat, or kick other players, make it dig, etc. But in this part, I will tell you how to make the bot itself. So, let's get started.

 

First, we run this command to init a new Node.JS project:

npm init -y

 

It will quickly make a new project for us. Now, after it's done, we make a new file called index.js.

 

Our first lines of code are:

const mineflayer = require('mineflayer')

 

We now added our mineflayer "library". Now, we want to make options for the bot. This will be made like that:

const options = {
	host: "server.com",
	username: "Blume"
}

 

If we want the bot to actually join the server we want it to, you need to change the "host" value to the server's domain or address IP.

If you want you can also change the username to anything you want. My bot is going to be called "Blume". 

 

Now, we need to create our bot using the options. How do we do that?

The answer is simple: One line of code.

 

const bot = mineflayer.createBot(options)

Quick explanation:
We used the mineflayer package to create the bot using our options we made before.

 

Now, we'll type some events. One of them will be on spawn:

bot.on("spawn", () =>{
	console.log("[*] Bot connected!")
	bot.chat("Hello world!")
})

 

See? Now we have a bot that will say something when spawned / joined! Great work!

 

Now we will make it listen to a command, for example "!givemeop" that will give the player OP (keep in mind the bot has to be opped first to make the command executor opped)

 

bot.on("chat", (message, username) => {
	if(username != bot.username){
		if(message == "!givemeop"){
			bot.chat("/op" + username)
		}
	}
})

 

Another quick explanation what we just coded:

- We coded an event listener (if I called it properly lol), which will detect any new messages in chat.

If the message sender's username is the bot's username, ignore it, because we don't want the bot to talk to itself and repeat the message all over again, right?

 

So if the username is not the bot's username, we make the bot type in the command for opp'ing the message sender's username.

 

That's all for today!
I hope you understood all of the tutorial.

If you have any questions, feel free to ask them below.

Cya!

 

Posts: 585

Threads: 23

Joined: Feb, 2021

Reputation: 9

  • 0

Replied

this is actually cool

https://cdn.discordapp.com/attachments/1003991455657893938/1004560712183595079/uqJXQIda.gif

https://cdn.discordapp.com/attachments/1003991455657893938/1004267056201474079/BANNER.png

Aja

Zenexya#2964

Mention

Posts: 1125

Threads: 126

Joined: Apr, 2021

Reputation: 0

  • 0

Replied

@Cyros Thanks for your feedback!

Posts: 501

Threads: 22

Joined: May, 2022

Reputation: 4

  • 0

Replied

cool but where does it get the account from?..

https://i.imgur.com/vExwpG0.png https://i.imgur.com/SKVU0ro.png https://i.imgur.com/tRWLZCV.png https://i.imgur.com/HnaTwfT.png https://i.imgur.com/Yg0OQyw.png https://i.imgur.com/MgmQBvj.png

SeizureSalad

i love femboys

Mention

Posts: 575

Threads: 30

Joined: Mar, 2021

Reputation: 14

  • 0

Replied

@Whoman probably spoofed

 

also bad js code moment smh

also i think you forgor the npm install commnad

bot.on('chat', (message, username) => {
	if (username !== bot.username && message === '!givemeop'){
               bot.chat("/op" + username)
	}
})

Aja

Zenexya#2964

Mention

Posts: 1125

Threads: 126

Joined: Apr, 2021

Reputation: 0

  • 0

Replied

@SeizureSalad the code that you just made is the same but you made one if, and its overcomplicated for new users. Both codes are okay :) 

Posts: 585

Threads: 23

Joined: Feb, 2021

Reputation: 9

  • 0

Replied

@Whoman Guessing it's a Cracked Account (You don't have to buy a account) for this

https://cdn.discordapp.com/attachments/1003991455657893938/1004560712183595079/uqJXQIda.gif

https://cdn.discordapp.com/attachments/1003991455657893938/1004267056201474079/BANNER.png

Posts: 501

Threads: 22

Joined: May, 2022

Reputation: 4

  • 0

Replied

@Aja

just learn keywords

https://i.imgur.com/vExwpG0.png https://i.imgur.com/SKVU0ro.png https://i.imgur.com/tRWLZCV.png https://i.imgur.com/HnaTwfT.png https://i.imgur.com/Yg0OQyw.png https://i.imgur.com/MgmQBvj.png

luxiferrwoo

! exprssn.sentiment#9999

Mention

Posts: 116

Threads: 25

Joined: May, 2022

Reputation: 10

  • 0

Replied

@Aja

lmao it's not overcomplicated? it's actually less complicated as it's less lines and more concise, it also teaches beginners to use !== and === when possible. I've had experience with JS myself and using strict comparisons is good practice.

13 | [c, cpp, lua, python]

! exprssn.sentiment#9999 | https://github.com/expressiongz

 

Posts: 94

Threads: 8

Joined: May, 2022

Reputation: 0

  • 0

Replied

Cool thread Vouch!


New Reply

Users viewing this thread:


( Members: 0, Guests: 1, Total: 1 )