Problems activating your account? Send notification email to: admin@post4vps.com
Host4Fun Budget VPS Hosting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A guide for beginners on how to write a Minecraft ChatBot
#1
Information 
In this post I will be showing how to make a really simple minecraft bot in node.js, that can be hosted on any node.js server!


First, we need to set things up!

1. Let's create our app folder. Let's name it "post4vps-chatbot". Then, we need to install some packages. We will be using minecraft-protocol as it's supporting all versions of Minecraft. Open an command prompt/terminal in your app folder, and type in:

npm install minecraft-protocol

Now, we can write code!

2. Create a .js file. It can be any name, but I'm going to use "server.js" as many hosting services search for that file. Now, open it.

Now, we will actually start programming!

We need to import the minecraft-protocol module. Include this in your file:

var mc = require('minecraft-protocol');

Now, initiate the client, and change the login information and the server IP. Don't include the password field if you wan't to login as an cracked account:
var client = mc.createClient({
   version: false, // Auto-Detect the version
   host: "examplemcserver.net", // << Change to your server IP!
   username: "post4vpsbot", // << You can choose any username if you are not using a paid account.
   password: "AFakePassword", // << If you are using a paid account, type the password to it here.
});

You can run your script, and it will join your server, but won't to anything and will just stand in one place, and then disconnect after a few minutes. Let's change that!

Let's make a custom "bot" command: "!ping". It will just echo out "Pong!".
client.on("chat", function(packet){
   var message = JSON.parse(packet.message)

   if(message.text.includes("!ping")){
       client.write('chat', {message: "Pong!"})
   }
})
This snippet listens any packets that are of type "chat". If the client recieves such packet, we know that the packet is in JSON format. Let's parse it, and then check if the message includes the word "!ping". If it does, let's write a packet, also of type chat, with a message of "Pong!".

Simple, right?
You can also execute server commands with this, for example, let's change our gamemode to spectator:
client.write('chat', {message: "/gamemode spectator"})
That was all! And all that we had to write was:
var mc = require('minecraft-protocol');

var client = mc.createClient({
  version: false, // Auto-Detect the version
  host: "examplemcserver.net", // << Change to your server IP!
  username: "post4vpsbot", // << You can choose any username if you are not using a paid account.
  password: "AFakePassword", // << If you are using
a paid account, type the password to it here.
});

client.on("chat", function(packet){
   var message = JSON.parse(packet.message)

   if(message.text.includes("!ping")){
       client.write('chat', {message: "Pong!"})
   }
})
Now, if we wan't to run this on a Forge (modded) Minecraft server, we need to make some modifications in our code. We need to install the package minecraft-protocol-forge, which is an addon for minecraft-protocol. Run this in the terminal/cmd (REMEMBER YOU NEED TO BE IN YOUR APPS FOLDER!):
npm install minecraft-protocol-forge
Now, let's add this line to the beggining of our file:
var autoVersionForge = require('minecraft-protocol-forge').autoVersionForge;
And add this after the client init:
autoVersionForge(client);

Now it will auto-detect your server mods, and send a packet to the server with those same mods, so your server will think you have the mods installed!
You can have some issues with this on some hostings.
Some node.js hostings detect if your server is running something on port 8080. If not, they shut down your script. To solve that issue, you need to write this in the beggining of the script:

var http = require('http');
http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type': 'text/plain'});
   res.write('Hello!');
   res.end();
 }).listen(8080);

And it should work properly!
If you found this tutorial helpful, please add a positive rating! Thanks! ^^
This thread was deleted and then moved to this category!
I'm just a Temmie, what did you expect?  ^^
Reply
#2
I am not following this. Where would this be even used? Like in Minecraft server or some kind of client?. Either way impressive tutorial. Many people will benefit from this.
No one knows what the future holds, that's why its potential is infinite
Reply
#3
A good example of usage would be the bots on 2b2t, a Minecraft server with no rules. Users program their bots to do crazy stuff, example: send a command named "!digdiamonds!", the bot will determine locations of diamonds on the map, then mine them. Then, the user could do "!goto [coordinates]" and then "!dropitems" and then the bot would drop all of it's items. Pretty useful, right?
Hmm... I could do a tutorial on that... Big Grin
I'm just a Temmie, what did you expect?  ^^
Reply
#4
i really do not suggest using bots for any game first of all you will make it unfair and you won't enjoy the game, in another way you will be lazy just making bots doing your stuff, in this case you will hate the game, and stop doing it, in another way also you can get punishment they can detect you and ban you for using bots.
Thanks to Post4VPS and Host4Fun for my amazing VPS 1 
Reply
#5
(08-11-2019, 08:02 PM)Melvin Wrote:  i really do not suggest using bots for any game first of all you will make it unfair and you won't enjoy the game, in another way you will be lazy just making bots doing your stuff, in this case you will hate the game, and stop doing it, in another way also you can get punishment they can detect you and ban you for using bots.

This is a chatbot not a idle bot.
Reply
#6
(08-11-2019, 08:03 PM)perryoo11 Wrote:  This is a chatbot not a idle bot.

My bad, even that it won't you live the original experience by spending time gathering making stuff, so i also do not recommend it.
Thanks to Post4VPS and Host4Fun for my amazing VPS 1 
Reply
#7
Seems that you are experienced at Minecraft
Can you help me at starting a server on CentOS 7?
Im also playing with 2 fps, u know how can i fix this?
My laptop specs info: https://www.amazon.com/compaq-presario-c...b002j49p6u
Gimme +rep Heart
[Image: img.php?userid=496]
Thanks For Post4VPS and Virmach for the amazing VPS 9
Reply
#8
(08-14-2019, 08:33 AM)youssefbasha Wrote:  Seems that you are experienced at Minecraft
Can you help me at starting a server on CentOS 7?
Im also playing with 2 fps, u know how can i fix this?
My laptop specs info: https://www.amazon.com/compaq-presario-c...b002j49p6u

if you want some help starting a mc server follow this tutorial:
https://www.vultr.com/docs/install-a-min...n-centos-7
Reply
#9
(08-14-2019, 08:33 AM)youssefbasha Wrote:  Seems that you are experienced at Minecraft
Can you help me at starting a server on CentOS 7?
Im also playing with 2 fps, u know how can i fix this?
My laptop specs info: https://www.amazon.com/compaq-presario-c...b002j49p6u

That laptop is ancient history. I remember having a COMPAQ decades ago. I suggest getting a new laptop if you want to keep up with today's standards. I'm using an APU and I get a few frame hiccups here and there. If you insist on trying to get out of 2 FPS with your current laptop you can try using OptiFine (for the correct Minecraft version).
Reply
 


Possibly Related Threads...
Thread Author Replies Views Last Post
  How to change minecraft server version through control panel Honey 0 310 12-11-2018, 02:52 PM
Last Post: Honey
  Competition - VPS for Windows beginners - shortest number of steps to set it up! deanhills 2 605 08-08-2018, 09:28 AM
Last Post: humanpuff69
  [Tutorial] How To Create Minecraft Server OldMeister 8 3,360 08-28-2017, 08:59 AM
Last Post: OldMeister
  [Tutorial] How to add Bukkit to Minecraft Server! OldMeister 2 1,283 08-28-2017, 08:57 AM
Last Post: OldMeister
  [Debian & Ubuntu] Full OpenGamePanel Guide [FOGPG] azureweb 1 2,792 11-04-2016, 04:15 PM
Last Post: YOuNeS_Dz

Forum Jump:


Users browsing this thread: 1 Guest(s)

Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - SSDBlaze - VPSlices - Abc-Hosters - Hyper Expert - Shadow Hosting - Bladenode - HostDoc - Hostlease


About Post4VPS

Post4VPS is a forum/destiny where you can Delploy Your Free VPSs just by the Power of Posts.

We Provide VPSs of many locations like Germany,US,Canada,France,London,etc.

We also Provide VPSs of Both Linux and Windows OS.