-
-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorial: Your First Bot
In this article I'm going to shown the basics of using Neos.js to build a bot account.
We will learn how to:
- Authenticate the Bot
- Set up Friend Request Handling
- Set up Command Handling using the CommandExtended Plugin
- Set up Error Handling
- Build a Basic Bot
This tutorial will assume you know the Very Basics of node, If you are brand new to Node I recommend this video.
Setup for Neos.js is quite simple, The package including many beta builds are available on NPM.
Run npm install @bombitmanbomb/neosjs
to add the library to your workspace. For pre-release builds append @version to neosjs
Next, We require the Contructor like so
const Neosjs = require("@bombitmanbomb/neosjs");
This constructor will let us create a New Neos Client, along with pass in Startup Variables (See New Neos)
const Neos = new Neosjs({OnlineState:"Online"}) //Optional Param
Now we have a new instance of the Client ready to use. Now we need to tell it What to do. Neos.js is an Asynchronous Library, meaning Most functions will return a Promise of information from the server. Most functions data must be accessed via await
or .then()
.
In neos, accounts can only send messages to users they are Friends with. Neosjs has a whole list of events that fire when things happen.
When the bot receives a Friend Request, this will fire the friendAdded
with the Friend object. This will also fire on login when the bot fetches friends, so we also need to check if its a request, or existing friend
With Neos.js we use .AddFriend
to accept or send a request.
Neos.on("friendAdded", (request)=>{
if (request.friendStatus === "Requested") { // check if request
Neos.AddFriend(request.FriendUserId)
}
})