Bots
In this section of the documentation, we will be building a simple bot script with MooMoo.js.
Getting required information
To build a bot, we need just need the BotManager, which is a tool which helps you keeping track of bots and lets you create new bots.
Getting started with the BotManager
We need the Bot class to make a new Bot.
const Bot = MooMoo.BotManager.Bot;
Creating a new Bot
we can create a new instance of Bot
, but be aware there are several options that you can pass to the constructor.
If the first argument is false or undefined, the bot will not have a set name, skin or moofoll.
const bot = new Bot();
This is one way of doing it, but I suggest that you use the second way, which is to use the options object.
const Bot = new Bot(true, {
name: "ExampleName", // name of the bot which is later used in the .spawn() method
skin: 1, // skin color of the bot, 1-7
moofoll: true // extra resources true / false
})
Joining a server
Right now the bot is not connected to any server, to connect to a server, we can use the Bot.join
method.
If we want to summon the Bot in our current server, we can use the Servermanager to get the current server.
const { region, index } = MooMoo.ServerManager.extractRegionAndIndex();
Now, we can use the Bot.join
method to join the server.
Bot.join([region, index]);
You can also pass in a string, which will be parsed by the BotManager.parseServer
method.
Bot.join("12:2:0");
Or, if you want to you can pass in an Object:
Bot.join({
region: 12,
index: 2
});
Spawning the bot
To know when the bot is connected, we can use the event connected
.
You can also implement your own system and use the bot's ws, but I don't recommend it.
Inside the connected
event, we can use the Bot.spawn
method to spawn the bot.
Bot.addEventListener("connected", () => {
Bot.spawn();
});
Now, your creativity is the limit, you can now start making your own bot.
There are a few methods that you should consider, so please check out Bot.md