简体   繁体   English

Pircbotx 通道 setMode() 在 main() 方法中不起作用

[英]Pircbotx channel setMode() not working in main() method

I'm trying to set mode to an IRC channel but PircBotX doesn't seems to execute the command when called in the main method.我正在尝试将模式设置为 IRC 通道,但 PircBotX 在 main 方法中调用时似乎没有执行该命令。 The command executes when I send the message (!setRModePlus) that I have set up in the code.当我发送在代码中设置的消息 (!setRModePlus) 时,该命令将执行。 Where am I wrong with my code?我的代码哪里错了?

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");



}

Thank you for any help you can offer.感谢您提供的任何帮助。 Sorry for my English.对不起我的英语不好。

Problem solved now.现在问题解决了。 I added onConnect method and send the command like this我添加了 onConnect 方法并发送这样的命令

 public void onConnect(ConnectEvent event) {

        event.getBot().send().mode("#mychannel", "+R");
        event.getBot().send().mode("#mychannel", "-R");


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM