我的 Twitch 机器人(使用 Pircbot)没有保持与频道的连接

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

我正在尝试创建一个 twitch 机器人,我想让它做的第一件事就是响应聊天消息。但是,当机器人连接到聊天室时,它似乎并没有保持连接状态。它可以正常发送聊天消息,但收不到。

如果你想看的话,这里是代码。我觉得我遗漏了一些我应该记住的基本知识,所以如果你能弄清楚那是什么,我很想知道。

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);
}

}

您用大写字母写了频道名称(“#AceLava”)。在 IRC 中,这是与#acelava 不同的频道 - Twitch 始终处理全小写的频道。只要改变它,你就会没事的。

与问题无关,但您可能想知道 twitch 将很快更改其后台消息服务™,并且不会通过 IRC 完成,因此您必须相应地更改您的机器人(以及我必须做的 >.< ).

如需了解更多信息并了解最新信息,请访问 http://discuss.dev.twitch.tv/