我正在尝试为我的 twitch 聊天制作一个机器人,但我在连接到聊天时遇到了一些问题。 我在以下位置阅读了一些关于图书馆的信息: http://www.jibble.org/pircbot.php 并尝试连接到我自己的聊天,但出现错误。
1462989951913 *** Connected to server.
1462989951915 >>>PASS oauth:cencoring oath.
1462989951915 >>>NICK FredsBot
1462989951915 >>>USER FredsBot 8 * :PircBot 1.5.0 Java IRC Bot - www.jibble.org
1462989952324 :tmi.twitch.tv NOTICE * :Error logging in
1462989962324 *** Logged onto server.
Connected!
1462989962324 >>>JOIN #mychannel
1462989962324 *** Disconnected.
如您所见,我在尝试登录时遇到错误,但它确实打印出已连接的消息,并在断开连接后打印出来。 到目前为止,我已经尝试过不同的誓言 key ,但没有任何运气。有没有人偶然发现这个问题? 这是我的代码:
import org.jibble.pircbot.*;
public class MyBot extends PircBot {
private static final String channelName = "#mychannel";
private final String botName = "FredsBot";
public MyBot() {
this.setName(botName);
this.setLogin(botName);
}
public String getchannelName() {
return channelName;
}
@Override
public void onMessage(String channel, String sender,
String login, String hostname, String message) {
if (message.equalsIgnoreCase("time")) {
String time = new java.util.Date().toString();
sendMessage(channel, sender + ": The time is now " + time);
}
}
@Override
protected void onConnect() {
System.out.println("Connected!");
joinChannel(channelName);
super.onConnect();
sendMessage(getchannelName(), "Hello, i am a bot");
}
我的主图是这样的
private static final String OAUTH = "myoath";
private static final String ADRESS = "irc.chat.twitch.tv.";
private static final int PORT = 6667;
public static void main(String[] args) {
MyBot bot = new MyBot();
bot.setVerbose(true);
try {
bot.connect(ADRESS, PORT, OAUTH);
// bot.onMessage(channelName, "Bot", channelName, channelName, channelName);
} catch (IOException ex) {
Logger.getLogger(MainFile.class.getName()).log(Level.SEVERE, null, ex);
} catch (IrcException ex) {
Logger.getLogger(MainFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
我刚刚核实了我的誓言和 channel 名称,所以请不要介意。我确实阅读了类似的帖子,但其中大部分都已解决,只是获得了新的誓言 key ,这对我没有帮助。
最佳答案
所以我发现了问题所在。我不知道我需要使用我在代码中声明的确切名称为机器人创建一个帐户。 愚蠢的错误。
关于java - 为 twitch 聊天创建一个机器人。获取连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37170562/