Pircbot onmessage not working

I’m trying to learn how pircBot works with Java. I’ve already programmed a working chat bot in python. I’m using Java to try and refresh my java knowledge. I’ve looked around and can’t find any other topics on this site that address this.
Here’s my current code:
Bot Code:

import java.io.IOException;
import org.jibble.pircbot.*;

public class MyBot extends PircBot {

private static String channel;

public MyBot() {
    this.setName("sato_chat");
}

public MyBot(String channel) {
	this.channel = channel;
}

public void sendmember() throws NickAlreadyInUseException, IOException, IrcException {
	this.sendRawLine("CAP REQ :twitch.tv/membership\r\n");
	this.sendRawLine("CAP REQ :twitch.tv/tags\r\n");
	this.sendRawLine("CAP REQ :twitch.tv/commands\r\n");
}

public void onMessage(String channel, String sender, String login, String hostname, String message) {
	System.out.println("On Message Handler");
	if (message == "Hi") {
		this.sendMessage(channel, "Hello");
	}
  System.out.println(channel + " " + sender + " " + message);
}

}

Main code:

import org.jibble.pircbot.*;

public class MyBotMain {

public static void main(String[] args) throws Exception {
    
    // Now start our bot up.
    MyBot bot = new MyBot("#satokaheni");
    
    // Enable debugging output.
    bot.setVerbose(true);
    
    // Connect to the IRC server.
    bot.connect("irc.chat.twitch.tv", 80, pass);
    bot.sendmember();
    bot.joinChannel("#satokaheni");
    
}

}

the on message handler doesn’t register when I send a message to the chat room. So I’m not sure what I’m doing incorrectly here.

Pircbot is old and doesn’t support many IRC features that Twitch users such as tags which might explain your issue. Unless you want to fork Pircbot yourself to add these features yourself I would recommend looking into other more modern libraries such as KICL: http://kitteh.org/

Thank you I will look into that.

PircbotX (with the X) might be another option as well although I haven’t used it personally. I do like that KICL has features specifically targeting Twitch which might be a reason to stick with that.

PircbotX sample: https://github.com/TwitchDev/chat-samples/tree/master/java

I would update to a new library, but if you want to stick to PircBot, you never set the name. Either in the constructor or before the connection you need to call the setName(String name) method of the PircBot class

Thanks,

I’ve started looking into kitteh to try and make it work.

I was messing with Pircbot a little bit and since it really hasn’t had an update in a while, it has fallen way behind Kitteh… Make sure to look for the random cat “sounds” on every heartbeat…

Looks like i’ll have to update the javadocs to use Kitteh :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.