我正在尝试使用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();

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

最佳答案

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();
        }
    }
}

10-06 03:07