(PircBotX、Java和Twitch)我应该如何应用这个对象?
我正在尝试使用Pircbotx作为Android应用程序的库。Pircbotx将专门用于Twitch.tv聊天,因此我按照说明添加了Twitch支持代码。我在配置对象方面遇到了困难,或者库的路径可能如何 原版: 奇怪的是,如果您注释掉addListneer(),问题就消失了 最后,如果根据AndroidStudio建议的更正更改构造函数,Pircbotx构造函数将不会接受该配置对象 谁能给我指一下正确的方向吗 复制/粘贴参考:(PircBotX、Java和Twitch)我应该如何应用这个对象?,java,android,object,constructor,irc,Java,Android,Object,Constructor,Irc,我正在尝试使用Pircbotx作为Android应用程序的库。Pircbotx将专门用于Twitch.tv聊天,因此我按照说明添加了Twitch支持代码。我在配置对象方面遇到了困难,或者库的路径可能如何 原版: 奇怪的是,如果您注释掉addListneer(),问题就消失了 最后,如果根据AndroidStudio建议的更正更改构造函数,Pircbotx构造函数将不会接受该配置对象 谁能给我指一下正确的方向吗 复制/粘贴参考: public void Connect()引发异常{ //配置
public void Connect()引发异常{
//配置我们希望机器人执行的操作
Configuration.Builder Configuration=new Configuration.Builder().setAutoNickChange(false)//Twitch不支持多个用户
.setOnJoinWhoEnabled(false)//Twitch不支持WHO命令
.setCapEnabled(true).addCapHandler(新启用的CapHandler(“twitch.tv/membership”)//twitch默认情况下不发送加入、部分和名称,除非您请求,请参阅https://dev.twitch.tv/docs/irc/guide/#twitch-irc能力
.addServer(“irc.twitch.tv”).setName(“MyTwitchUsername”)//您的twitch.tv用户名
.setServerPassword(“oauth:bigAlphanumericString”)//您的oauth密码来自http://twitchapps.com/tmi
.addAutoJoinChannel(“#vgbootcamp”)//某些抽搐通道
.addListener(新的MyListener());
//您的配置的其余部分。。。
//使用配置创建我们的bot
PircBotX bot=新的PircBotX(配置);
//连接到服务器
bot.startBot();
}
在前面添加以下行,然后重试
Configuration _configuration = configuration.buildConfiguration();
PircBotX bot = new PircBotX(_configuration);
PircBotX
对象需要的是Configuration
对象,而不是Configuration.Builder
对象
实际上,您应该将生成器对象重命名为builder
,如下所示
public void Connect() throws Exception {
//Configure what we want our bot to do
Configuration.Builder builder = new Configuration.Builder().setAutoNickChange(false) //Twitch doesn't support multiple users
.setOnJoinWhoEnabled(false) //Twitch doesn't support WHO command
.setCapEnabled(true).addCapHandler(new EnableCapHandler("twitch.tv/membership")) //Twitch by default doesn't send JOIN, PART, and NAMES unless you request it, see https://dev.twitch.tv/docs/irc/guide/#twitch-irc-capabilities
.addServer("irc.twitch.tv").setName("MyTwitchUsername") //Your twitch.tv username
.setServerPassword("oauth:bigAlphanumericString") //Your oauth password from http://twitchapps.com/tmi
.addAutoJoinChannel("#vgbootcamp") //Some twitch channel
.addListener(new MyListener());
//The rest of your config...
//Create our bot with the configuration
Configuration configuration = builder.buildConfiguration();
PircBotX bot = new PircBotX(configuration);
//Connect to the server
bot.startBot();
}
在前面添加以下行,然后重试
Configuration _configuration = configuration.buildConfiguration();
PircBotX bot = new PircBotX(_configuration);
PircBotX
对象需要的是Configuration
对象,而不是Configuration.Builder
对象
实际上,您应该将生成器对象重命名为builder
,如下所示
public void Connect() throws Exception {
//Configure what we want our bot to do
Configuration.Builder builder = new Configuration.Builder().setAutoNickChange(false) //Twitch doesn't support multiple users
.setOnJoinWhoEnabled(false) //Twitch doesn't support WHO command
.setCapEnabled(true).addCapHandler(new EnableCapHandler("twitch.tv/membership")) //Twitch by default doesn't send JOIN, PART, and NAMES unless you request it, see https://dev.twitch.tv/docs/irc/guide/#twitch-irc-capabilities
.addServer("irc.twitch.tv").setName("MyTwitchUsername") //Your twitch.tv username
.setServerPassword("oauth:bigAlphanumericString") //Your oauth password from http://twitchapps.com/tmi
.addAutoJoinChannel("#vgbootcamp") //Some twitch channel
.addListener(new MyListener());
//The rest of your config...
//Create our bot with the configuration
Configuration configuration = builder.buildConfiguration();
PircBotX bot = new PircBotX(configuration);
//Connect to the server
bot.startBot();
}
您的
MyListener
类是否实现了Listener
?公共静态类MyListener扩展了ListenerAdapter{}。。。。这些IRC库给我带来了很多麻烦。我最终写了我自己的。你的MyListener
类实现了Listener
?公共静态类MyListener扩展了ListenerAdapter{}。。。。这些IRC库给我带来了很多麻烦。我最终写了我自己的。