我使用PircBot API的机器人没有连接到服务器

时间:2012-12-19 15:20:36

标签: java sockets bots

我决定为我的Twitch.TV频道编写一个IRC bot。它使用PircBot API。

尝试运行时收到以下错误消息:

java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown 
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.jibble.pircbot.PircBot.connect(PircBot.java:140)
    at NewbieBot.main(NewbieBot.java:19)

我到目前为止的代码是:

import org.jibble.PircBot.*;
import java.io.IOException;

public class NewbieBot extends PircBot {
    public NewbieBot() {
        this.setName("newbiebot");
    }

    public void main(String[] args) {
        NewbieBot bot = new NewbieBot();
        bot.setVerbose(true);
        bot.setAutoNickChange(true);
        try {
            System.out.println("Attempting to join server");
//            bot.connect("newbiedoodle.jtvirc.com", 6667, "newbieschannel");
            bot.connect("irc.esper.net", 6697, "newbiebot");
        } catch (NickAlreadyInUseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IrcException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (bot.isConnected()) {
            System.out.println("Connected!");
        }
        else {
            System.out.println("Failed to connect.");
            return;
        }
    }
}
public void onMessage(String channel, String sender, String login, String hostname, String message) {
    if (message.equalsIgnoreCase("test!") {
        sendMessage(channel, "Testing!");
    }
    if (message.equalsIgnoreCase(">cmds")) {
        sendMessage(channel, "   ------ Commands ------   ");
        sendMessage(channel, ">cmds: Show the bot commands");
        sendMessage(channel, ">rules: Show the stream rules");
        sendMessage(channel, ">mods: Show list of online mods");
        sendMessage(channel, ">info: Show channel info");
    }
}

如果有人能弄清楚什么是错的,请告诉我。

注意:我在家测试了这个并完全禁用了防火墙,但它仍然无法连接。

0 个答案:

没有答案