[英]Creating a Bot for twitch chat. Getting a connection Error
I'm trying to make a bot for my twitch chat but i'm having some problems to connect to the chat with it.我正在尝试为我的 twitch 聊天制作一个机器人,但我在连接到聊天时遇到了一些问题。 I read a bit about the library at: http://www.jibble.org/pircbot.php And tried to connect to my own chat but i'm getting an error.
我在以下位置阅读了一些有关该库的信息: 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.
As you can see i'm getting an error while trying to login, but it does print out the connected message and after it disconnects.如您所见,我在尝试登录时遇到错误,但它确实会打印出已连接的消息,并在断开连接后打印出来。 So far i've tried different oath keys without any luck.
到目前为止,我已经尝试了不同的誓言钥匙,但没有任何运气。 Have anyone stumble across this problem?
有没有人偶然发现这个问题? Heres my code:
这是我的代码:
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");
}
My main looks like this我的主要看起来像这样
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);
}
}
i've just cencored my oath and channel name so dont mind that.我刚刚确认了我的誓言和频道名称,所以不要介意。 I did read up on similar post but most of them were solved just but getting a new oath key and it did not help me.
我确实阅读过类似的帖子,但其中大部分问题都已解决,只是获得了新的誓言密钥,但对我没有帮助。
So i found out what the problem was.所以我发现了问题所在。 I had no idea that i needed to create an account for the bot with the exact name which i had declared in my code.
我不知道我需要使用我在代码中声明的确切名称为机器人创建一个帐户。 Silly mistake.
愚蠢的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.