简体   繁体   中英

How to send message to chat in IRC server?

How to send message to chat in IRC server? Here is API server, and description how to connect to this server, but I don't know how to implement it in java.

At first I need to connect to his irc server with login and password. And then send message. I found PircBot to connect to IRC server, but can't connect... to this API

  1. How to connect to IRC server?
  2. How to send message to IRC server?

I tried run in Client for this library

java Client -server irc.twitch.tv:6667 -pass oauth:1vuwah03rawwpgs5u38y -nick nick -user nick -name nick -ssl

Exception in thread "main" java.lang.NoClassDefFoundError: org/schwering/irc/lib
/IRCConnection
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.schwering.irc.lib.IRCConnection

        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

If you have a look at the PircBot documentation, you can see the bits you might need are:

to make the connection: http://www.jibble.org/javadocs/pircbot/org/jibble/pircbot/PircBot.html#connect(java.lang.String , int)

to send the password: http://www.jibble.org/javadocs/pircbot/org/jibble/pircbot/PircBot.html#sendRawLine(java.lang.String)

I'm going to hazard a guess as I've never connected to twitch, but I'd imagine your connection lines would look like:

bot.connect("irc.twitch.tv",6667);
bot.sendRawLine("PASS oauth:twitch_oauth_token");
bot.sendRawLine("NICK yournickname");

edit:

and to answer the question in the title:

Once connected to the server, PircBot has a sendMessage(String channel,String message) method, which will, as you would expect, send a message to the channel.

I tried the code by C_STo, but it didn't work for me. This is the code that worked for me:

bot.connect("irc.chat.twitch.tv", 6667, "oauth:your_auth_code_here");

You provide an auth code as a parameter to connect method. This approach worked for me. But before that, you should have your name and user set. You do that with these commands:

bot.setName("your_username");
bot.setLogin("again_your_username");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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