以下代码成功连接到Twitch的IRC,并触发onConnect方法,这就是一切停止的地方。因为pIRCbot启用了verbose,所以我可以看到它确实在连接后发送JOIN #twitchplayspokemon
,但规范规定我应该立即得到一个带有相同文本的响应,后面跟着一个用户列表(这将触发onJoin和onUserList方法),但这并没有发生。
我还尝试连接到我的频道并使用
发送消息joinChannel("#[mychannelname]");
sendMessage("#[mychannelname]", "Hello World");
所有这些都只是发送两个JOIN命令,并且永远不会加入,也不会在聊天中出现消息。
我使用的教程/参考资料是http://help.twitch.tv/customer/portal/articles/1302780-twitch-irc
其他回应也没有被输出。我得到了MOTD,但没有看到"结束/MOTD命令"。
import org.jibble.pircbot.*;
public class MyBotMain extends PircBot {
public static void main(String[] args) throws Exception {
MyBotMain bot = new MyBotMain();
bot.setVerbose(true);
bot.setName("[myname]");
bot.setLogin("[myname]");
try {
bot.connect("irc.twitch.tv", 6667, "oauth:db4aai4mh474ikbgzzuh76fv67n"); // Not the key I'm using
} catch (NickAlreadyInUseException e) {
System.err.println("Nickname is currently in use");
} catch (IrcException e) {
System.err.println("Server did not accept connection");
e.printStackTrace();
}
}
@Override
protected void onConnect() {
System.out.println("Connected!");
joinChannel("#witchplayspokemon");
super.onConnect();
}
@Override
protected void onJoin(String channel, String sender, String login, String hostname) {
System.out.println(login + " joined channel " + channel);
super.onJoin(channel, sender, login, hostname);
}
@Override
protected void onUserList(String channel, User[] users) {
for (User user : users) {
System.out.println(user);
}
super.onUserList(channel, users);
}
}
你的代码运行得很好,唯一的问题是你试图加入的频道是"witchplaysportmon"而不是"twitchplayspoartmon"onUserList(字符串频道,User[]用户)只给我一个用户,但我最近在自己的Bot上遇到了这个问题,所以我还不确定原因。