PircBot IRC Bot FAQ

Frequently Asked Questions

Back to the PircBot IRC Bot home page.

PircBot is a Java IRC Bot Framework that allows you to create your own custom IRC bots quickly and easily. This document covers some of the questions that are asked most often. If there are any other questions that you would like to see on this page, then feel free to make suggestions via email.

I don't know where to begin!

If you're really stuck, then there are a few things that you must look at first:

How do I make the bot rejoin a channel when it's kicked?

You can do this automatically by overriding the onKick(...) method and placing something like this in it:

if (recipientNick.equalsIgnoreCase(getNick())) {

Notice that we are checking that it was actually our bot that got kicked before we try to rejoin!

How do I detect when my PircBot changes its nick?

There is no need to do this any more since PircBot version 1.0.0, which automatically handles nick changes internally. The current nick of the bot can always be obtained by calling the getNick() method.

How can I send a message to the server immediately?

When you send normal messages by using the sendMessage(...) method, each message is added to an internal queue before being sent to the IRC server. This is so that the rate of message sending can be controlled in order to prevent the IRC server from thinking that we are trying to flood it. If you try to send lots of messages at the same time, the queue can start to fill up, making it seem as though any message you send at this point takes a while to get sent to the IRC server. To bypass the queue and send lines directly to the IRC server, you can call the sendRawLine(...) method. For example, to send a hello notice to a user called "Dave", you would call sendRawLine("NOTICE Dave :hello");

Does PircBot support multiple IRC servers?

Yes. PircBot can be used with multiple IRC servers. All you have to do is create a new instance of PircBot for each server that you wish to connect to. You can create each PircBot within some base class which can store them all and thus be used to allow each individual PircBot to communicate with each other.

How do I get my bot to reconnect to the IRC server?

The onDisconnect() method is called whenever the bot becomes disconnected from the IRC server, so you can override this method and make it so that it calls the appropriate methods to connect to the IRC server again and join the required channels. In case the reconnection attempt fails, you might like to consider placing this kind of thing in a while loop so it keeps trying until it's connected.

while (!isConnected()) {
    try {
    catch (Exception e) {
        // Couldn't reconnect!
        // Pause for a short while...?

Don't forget to put in a small delay between attempts, otherwise things could go a bit wibbly if it keeps failing the connection process!

Where can I get information about the IRC protocol?

You can read the IRC Requests for Comments at http://www.irchelp.org/irchelp/rfc/. As a general rule, all IRC clients and servers should abide by the rules and recommendations specified within these documents.

I want to do something that PircBot doesn't support yet

If you want to act on an event from the IRC server, but the PircBot framework does not provide a method to deal with it yet, then you have one of two options:

How can I stop my bot from flooding the IRC server?

The setMessageDelay(...) method can be used to set the minimum delay between each message that is sent to the IRC server. The default value is 1000ms and is generally suitable on most servers. If you do experience problems with being kicked for flooding, then you may like to consider raising this delay.

My DCC Chat sessions don't seem to work

If you find that DCC connections cannot be established, then make sure that neither end of the connection is behind a firewall that prevents traffic via TCP sockets. If you are using NAT software, then bare in mind that it is the recipient that connects to the sender, rather than the other way around. If you are running PircBot on a Linux system, then make sure that you don't have a line like yourhostname in /etc/hosts, otherwise this will cause the PircBot to be unable to determine the true IP address of the machine.

How do I find out who is in a channel?

You can override the onUserList method to get a list of users when your bot joins a channel. To obtain this list at a later time, you can call the getUsers method, which takes a channel name as an argument. Your bot must be in a channel in order to know who is in it.

How do I install PircBot on FreeBSD?

Firstly, if you do not know what FreeBSD is, then you needn't read the rest of this - it is only useful for those who are trying to install PircBot onto a FreeBSD operating system.

Pircbot is in the FreeBSD ports under irc/pircbot. You can view it on freshports at http://www.freshports.org/irc/pircbot/. To install this, you need to first get your ports collection up to date. Then, assuming you have already installed Java, type the following commands :-

% cd /usr/ports/irc/pircbot
% make install clean

Pircbot will then have been installed. Follow this guide on how to set up java. You'll want to add /usr/local/share/java/classes/pircbot.jar to your classpath. Documentation will have been installed in /usr/local/share/doc/pircbot.

Then, when there's a new release of pircbot all you need to do is upgrade your installed packages and you'll have the new pircbot ready to use. Tim Bishop is the man responsible for jibbling all this together.


Search this site


Copyright Paul Mutton 2001-2013
Feedback welcomed

Web Hosting

Web Hosting