Parsbot | Discord Bot Tutorial Node.js | Part 6
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
Source
Useful Links
What Will I Learn?
New Command Account Follow and followers (accfow)
New Command Account Last Vote (accltvote)
Run and test Parsbot
Requirements
Node.js (Download)
A text editor (e.g Visual Studio Code)
Difficulty
- Intermediate
Curriculum
Parsbot | Discord Bot Tutorial Node.js | Part 3
Parsbot | Discord Bot Tutorial Node.js | Part 4
Parsbot | Discord Bot Tutorial Node.js | Part 5
For other tutorials you can visit my profile.
Tutorial Contents
In this tutorial we will add two new command for our bot. Our first command will show the account follow and followers. Our second command will show the last vote date and time of the account.
New Command Account Follow and followers (accfow)
Now we will add a new command to see Steem account follow and followers.
Now, let's write the "else if" section of our command "app.js" file.
Code:
else if (msgorg.startsWith(prefix + 'accfow')) {
}
Now we will create a variable called "accountname". We will receive our message in this variable, and we will delete the "$accfow " section.
Code:
let accountname = msgorg.replace(prefix + 'accfow ','');
In this way we have successfully acquired steem account name.
Now we can create a request for follow and followers with steem.js.
Code:
steemjs.api.getFollowCountAsync((accountname),
function(err,fresult)
{
});
Okay, now I declare two variable "follower_count" and "following_count". And I am making assignments from our request.
Code:
var follower_count = fresult.follower_count;
var following_count = fresult.following_count;
Now I define message and send.
Code:
var follower_count = fresult.follower_count;
var following_count = fresult.following_count;
Now, I am adding "if invalid account id" part for invalid account names.
Code:
if(fresult["0"] === undefined)
{
console.log("Invalid Acccount ID");
message.channel.send('Invalid Acccount ID');
}
else
{
var follower_count = fresult.follower_count;
var following_count = fresult.following_count;
var accfow = (accountname + " Follower:" + (follower_count) + ' Following:' + following_count);
message.channel.send(accfow);
}
We say that if result (our account data) not defined, print "Invalid Acccount ID" message to our console and send the "Invalid Acccount ID" messsage to channel. Else get the account follow and followers info and send message.
All codes:
else if (msgorg.startsWith(prefix + 'accfow')) {
let accountname = msgorg.replace(prefix + 'accfow ','');
steemjs.api.getFollowCountAsync((accountname),
function(err,fresult)
{
if(fresult["0"] === undefined)
{
console.log("Invalid Acccount ID");
message.channel.send('Invalid Acccount ID');
}
else
{
var follower_count = fresult.follower_count;
var following_count = fresult.following_count;
var accfow = (accountname + " Follower:" + (follower_count) + ' Following:' + following_count);
message.channel.send(accfow);
}
});
}
In this code if received message is "$accfow steemaccountname" we will send the steemaccountname follower count and follow count message using our bot and Steem API.
We have integrate successfuly our bot into Steem account Follow and followers control.
New Command Account Last Vote (accltvote)
Now we are adding our second command to see the last vote date and time of the account.
Code:
else if (msgorg.startsWith(prefix + 'accltvote')) {
}
Now we will create a variable called "accountname". We will receive our message in this variable, and we will delete the "$accltvote " section.
Code:
let accountname = msgorg.replace(prefix + 'accltvote ','');
In this way we have successfully acquired steem account name.
Now we can create a request for account last vote date and time.
Code:
else if (msgorg.startsWith(prefix + 'accltvote')) {
let accountname = msgorg.replace(prefix + 'accltvote ','');
steemjs.api.getAccounts([accountname],
function(err,result)
{
if(result["0"] === undefined)
{
console.log("Invalid Acccount ID");
message.channel.send('Invalid Acccount ID');
}
else
{
var lastvote = moment(result[0].last_vote_time).add('hours', 3);
var lastvotemes = accountname + " Last Vote:" + (lastvote.format("YYYY-MM-DD HH:mm"));
message.channel.send(lastvotemes);
}
});
}
In our code above, we sent the api our steem account name. We created our request function to capture the incoming data (result). We say that if result (our account data) not defined, print "Invalid Acccount ID" message to our console and send the "Invalid Acccount ID" messsage to channel.
Else I get the date and time of the account last vote.And for Turkey UTC add 3 hours (you can customize it for yourself) and send "accountname + Last Vote: + (lastvote)" message.
In this code if received message is "$accltvote steemaccountname" we will send the steemaccountname last vote date and time message using our bot and Steem API.
We have integrate successfuly our bot into Steem account last vote date time control.
Run and test Parsbot
Okay, now we have to run and test our discord bot.
Open cmd and write "cd yourbotdirectory" and press enter. I write "cd C:\Users\gffdg\Desktop\Discord Pars Bot\parsbot".
Now we will run our app.js file with node.
node app.js
Our bot started successfully and printed "Pars Bot started" message on our ready event.
We came to the end of our education. Thank you for your attention.
Posted on Utopian.io - Rewarding Open Source Contributors












Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @kizilelma, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Hey @pars11 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x