Search code examples
javairc

My Twitch bot (using Pircbot) doesn't stay connected to a channel


I'm trying to create a twitch bot, and the first thing I'm trying to make it do is respond to chat messages. However, when the bot connects to the chat room, it doesn't seem to stay connected. It sends chat messages fine, but it doesn't recieve them.

Here's the code if you want to look at it. I feel like I'm missing something basic that I should've remembered, so if you can figure out what that is I'd like to know.

package me.acezephyr.lavabot;

import java.io.IOException;

import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException;
import org.jibble.pircbot.PircBot;

public class LavaStreamBot extends PircBot {

private static LavaStreamBot INSTANCE = new LavaStreamBot();

public static void main(String[] args) {
    INSTANCE.setVerbose(true);
    INSTANCE.setName("LavaStreamBot");
    try {
        INSTANCE.connect("irc.twitch.tv", 6667,
                "oauth:******************************");
    } catch (NickAlreadyInUseException e) {
        System.err
                .println("Tried to join Twitch server, but someone else online already has the nick LavaStreamBot.");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IrcException e) {
        e.printStackTrace();
    }
    join("#AceLava");
}

public static void join(String channel) {
    INSTANCE.joinChannel(channel);
    INSTANCE.sendMessage(channel, "LavaStreamBot is now in this channel.");
}

@Override
public void onConnect() {
    System.out.println("Connected to server");
    super.onConnect();
}

@Override
public void onMessage(String channel, String sender, String login, String hostname, String message){
    System.out.println("Got a message!");
    super.onMessage(channel, sender, login, hostname, message);
}

}


Solution

  • You wrote the channel name ("#AceLava") with capitals. In IRC, this is a different channel than #acelava - Twitch always handles the channels with all lowercase. Just change that and you'll be all fine.

    Not related to the question, but you might want to know about the fact that twitch will change their Background messaging service soon™ and it won't be done via IRC so you'll have to change your bot accordingly (as well as I'll have to do >.< ).

    For more information and to keep up to date, visit http://discuss.dev.twitch.tv/