gpt4 book ai didi

java - Pircbotx channel setMode() 在 main() 方法中不起作用

转载 作者:行者123 更新时间:2023-12-01 17:51:18 24 4
gpt4 key购买 nike

我正在尝试将模式设置为 IRC channel ,但在主方法中调用时 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");


}

关于java - Pircbotx channel setMode() 在 main() 方法中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60791314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com