方法connect()从类型PircBotX不可见

时间:2014-09-09 21:46:56

标签: java

我正在尝试使用PircBotX创建一个机器人,但是我甚至无法开始制作它。仅使用基本示例代码,我无法使connect()方法起作用,它总是在标题中提到的编译时给出错误。这是我正在使用的代码:

import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;

public class MyBot {
    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration.Builder()
        .setName("PircBotX") //Set the nick of the bot. CHANGE IN YOUR CODE
        .setLogin("LQ") //login part of hostmask, eg name:login@host
        .setAutoNickChange(true) //Automatically change nick when the current one is in use
        .setCapEnabled(true) //Enable CAP features
        .setServerHostname("irc.freenode.net")
        .addAutoJoinChannel("#pircbotx") //Join the official #pircbotx channel
        .buildConfiguration();
        PircBotX bot = new PircBotX(configuration);

        //Connect to server
        try {
            bot.connect();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

bot.connect();

发生错误

PircBotX可以在其Google代码页上找到:https://code.google.com/p/pircbotx/

1 个答案:

答案 0 :(得分:1)

docs上,有一种名为startBot()的方法,是否应该使用?

void startBot() Start the bot by connecting to the server.

import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;

public class MyBot {
    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration.Builder()
        .setName("PircBotX") //Set the nick of the bot. CHANGE IN YOUR CODE
        .setLogin("LQ") //login part of hostmask, eg name:login@host
        .setAutoNickChange(true) //Automatically change nick when the current one is in use
        .setCapEnabled(true) //Enable CAP features
        .setServerHostname("irc.freenode.net")
        .addAutoJoinChannel("#pircbotx") //Join the official #pircbotx channel
        .buildConfiguration();
        PircBotX bot = new PircBotX(configuration);

        //Connect to server
        try {
            //bot.connect();
            bot.startBot();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}