Login

Categories

Archives

Create an IRC Bot with NodeJS

IRC was the best 10 years ago, now other softwares have eclipsed, but many savvy people keep using it for proper communication with special individuals. So, if you never heard or configured eggdrops, this is something similar.

So first you will need to install NodeJS, and I will consider that you already have it, then you should have NPM also installed, then just install the irc library:

npm install irc

Once you have that, you need to specify that you are using this module and then set the configure on connecting to know which channels the bot will join automatically, and then set up the port, which is not a regular port for IRC but you need to set something more stable for a bot.

So as you see, first we set up the server, then the nick, and then we open encapsulation to add the channels, the port and a mode where we can see what is going on on your console.

NOTE: You might get some errors when connecting, but try again and again. When you are able to connect, no matter if you sleep your localhost, it will continue connecting. Also this is for leaving it working on a VPS or shell so you have a always online bot.

But now that you have your bot online, what’s next? You need to know wtf is going on in the channels that you join or the PM you receive, and for that we have listeners.

Before getting into this I will explain the functions we have available so we can use them when we get events on the listeners:

JavaScript

1

2

3

4

5

6

7

8

bot.join('#yourchannel yourpass');// this will join a channel with a pass (or no pass)

bot.part('#yourchannel');//part a channel

bot.say('#yourchannel',"I'm a bot for w0b!");// send a message to a channel

bot.whois(nickname,function(whois){

console.log(whois);// you need this callback to log the results once it finished doing the whois

bot.notice(target,"your message for the notice");//target is either a nickname or a channel