我正在尝试将模式设置为IRC通道,但在main方法中调用PircBotX时似乎不执行该命令。当我发送在代码中设置的消息(!setRModePlus)时,该命令将执行。我的代码在哪里出错?
import org.pircbotx.Channel;
import org.pircbotx.Configuration;
import org.pircbotx.PircBotX;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.types.GenericMessageEvent;
public class MyListener extends ListenerAdapter {
static Channel channel = null;
static PircBotX bot = null;
@Override
public void onGenericMessage(GenericMessageEvent event) {
if (event.getMessage().startsWith("!setRModePlus")) {
channel = bot.getUserChannelDao().getChannel("#mychannel");
channel.send().setMode("+R");
}
if (event.getMessage().startsWith("!setRModeMinus")) {
channel = bot.getUserChannelDao().getChannel("#mychannel");
channel.send().setMode("-R");
}
}
public static void main(String[] args) throws Exception {
//Configure the bot
Configuration configuration = new Configuration.Builder()
.setName("myname")
.addServer("myserver")
.setNickservPassword("mypassword")
.addAutoJoinChannel("#mychannel")
.addListener(new MyListener())
.buildConfiguration();
//Create bot with the configuration
bot = new PircBotX(configuration);
bot.startBot();
channel = bot.getUserChannelDao().getChannel("#mychannel");
channel.send().setMode("+R");
}
谢谢您能提供的任何帮助。对不起,我的英语。
问题已解决。我添加了onConnect方法并像这样发送命令
public void onConnect(ConnectEvent event) {
event.getBot().send().mode("#mychannel", "+R");
event.getBot().send().mode("#mychannel", "-R");
}