Search Tools Links Login

IRC bot Tutorial

This allows users to write their own IRC bot.

Original Author: br1m5t0n3


IRC Bot tutorial

These colors denote: what the server sends, what the client sends and pieces of code

Many of you have asked, "How did you make that?" referring to my IRC bot made in vb. Well, Let me explain. This tutorial will explain the process of making an IRC bot in any language but I'll use VB and the Winsock control for examples. Before you do any coding, go get the IRC RFC, it's a guidebook to the protocol and really helpful.

The first thing to need to do is to create a form and drag in 1 Winsock control. The majority of your code will go in the _DataArrival sub, but it doesn't have to.

Once you got the controls set up, switch to the code view, this is where you will hangout for the rest of your time with me....

The first thing your bot should do is figure out what its name is, along with its real name and its username. I recommend creating a class to store these in. The class that I made was a simple one useing the wizard. It contained 4 properties that were strings, nick, username, realname, and ip. Just walk through with the wizard and set up those string properties, it's that easy. I will refer to this class as "Person", and you will want to "Dim bot as New Person". Now you have declared bot.nick, bot.realname, bot.username, you are ready to connect to a server. Well what are you waiting for?

Winsock1.connect "", "6667"

Now that wasn't that hard was it? If you've been watching what comes in you'll notice that you've already started to receive information. But how does the server know who you are? Tell it! When the Winsock connects, the _Connect sub fires, in the sub you want to send the bot.* information to the server, but there is a special way that it has to be sent.



Ahh! What's this? IRC protocol! Just fill in the blanks and send it to the server, use the .remotehost property for the . Your code should look something like this...

USER "bot.nick" "" "" "bot.realname"

NICK "bot.nick"

But you have to encapsulate the string in double quotes, terminate all original double quotes (that gets messy) then send it, so you get something that ends up looking like this...

winsock1.send "USER " & bot.Nick & " " & """" & """" & " " & """" & Winsock1.RemoteHost & """" & " " & bot.realname & vbCrLf

winsock1.send "NICK """ & bot.nick & """" & vbCrLf

Yes, that's four (4) double quotes (") near the end of that last statement

Well, now that the server knows who you are, it will want to ping you, to make sure that you're still alive....

PING :12345678

Well? Say pong back

PONG :12345678

But you have to change the PING to PONG and then send it to Winsock

winsock1.send replace(incommingstring, "PING", "PONG") & vbCrLf

But that's only when the start of the incommingstring is "PING", so throw in an If test and you're good to go...

If Left(incommingstring, len("PING")) = "PING" Then


End If

Wohhh! What's all this information that the server's sending!? It's the message of the day, or MOTD for short you can disregard most if not all of it. But look at the syntax of these commands, they all start with a : and the name that the server wants to be called... you'll have to remember that to tell if it's the server sending you messages or someone is trying to send you a message.

Wow, we've done a lot in a few lines of code, we've connected to a server, told it who we are, and now what? Join a channel!


Gee, now that wasn't that hard was it? More information coming! Looks like a listing of the names in the channel!

: 372 @ @oldbot @X

Well! It looks like our buddy X and oldbot are in here, how nice of them to protect the channel for us...

: 321 TOPIC :Welcome to

At least there is a topic here, X does do a good job of keeping the topic... Let's change it!

TOPIC :Testing bot

Now that wasn't so hard?

: 417 :You're not channel operator

I really wish they would change the grammar in that error message, but it's basically telling us that we're not a channel operator, just a normal user. So, let's get ops. To do so, we must send a message to our good buddy oldbot.

PRIVMSG oldbot :login password

The PRIVMSG command refers to a simple text message the first parameter can be a user or a channel

:oldbot! NOTICE :Password Accepted

It's that nice our old bot has informed us that it liked our password, now let's get ops.


Another message to a channel

:oldbot! MODE +o

Warning, this isn't as confusing as it looks. It's just saying that oldbot changed the mode of to +o, +o just happens to require a channel, which is , now let's kick out our oldbot

KICK oldbot

:!@ KICK oldbot

You'll notice that almost every command that we send to the server is echoed back, when it's not echoed back and it should be you should ping the server just to make sure that it's still there and someone hasn't unplugged you

PING :12345

PONG :12345

Good, the server's still up. Well, you can continue this sending and receiving of commands 'til your hearts content, but for the purpose of this tutorial, let's leave IRC with a message for all to see

QUIT :I learned the basics of the IRC Protocol!

This is the end of the tutorial, but not the extent of the IRC protocol, there are two other protocols embedded within IRC, CTCP and DCC, client-to-client-protocol and direct-client-to-client. CTCP goes through the server, DCC doesn't. CTCP is used for version identification and client pings, DCC is used for the sending of files, and chat that doesn't go through the server.


Link to source code for a vb irc bot.

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 104 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.