Bot dont get incomming messages after x minutes

Hey guys, i have the following situation:
i connect (with a java lib) into the twitch chat and have no problems.
after a few minutes i dont get any incomming message. the bot is always connectet to twitch and can send messages into the chat (al other can see it) but all messages from other (public chat or whisper) dont get to the bot.

have you any idea? :frowning:

Are you sure that the incoming message thread is still running? Something might cause the incoming thread to stop (exceptions it the similar) while the sending thread is still running.

What library are you using?

i’m not sure… i debug all possible on-method for messages of the lib but dont get anything :confused:

i use the PircBot lib

Are you still receiving PINGs?

yes i get… but after halb an hour wothout incomming message i dont get any ping… but this problem i think is an effect of the main problem with no incomming message…

Do you send PONGs? If you do not respond to the PINGs, you’ll get disconnected what would explain your issue.

And messages in twitch-chat are sent as Privmsg to the bot, make sure you are listening to them and not to some public messages, idk how the pircbot interface handles those.

Do you mind sharing your java source code? I suppose the issue is somewhere in there. If you do not find success with your current library I would suggest writing your own code to connect to the servers, there are plenty of guides on how to do that.

the lib send pong by himself, but i checked and on each ping form twitch the lib send pong back
but sometimes i knog the time between the pings are so long… at the begining i get even disconnect a few seconds befor i get a ping… but last time i dont have this anymore

i’ll try to write my own code but i’m to stubed for it :confused: it never work… thats the reson i use a external lib

Well using a library for that is the common way to go, why rewrite code that already exists. But it would help a lot if you would share the part of code you have written, where the connection is established, used and maintained.

You can try my chat library if it works better. No use writing it all by yourself.

There is nothin spezial

package irc;

// ##### CLASS #####
public class IrcPircBot extends PircBot {
    public String channel = null;
    public String server = null;
    public String login = null;
    public String pass = null;
    public String nick = null;

    public void start() {
        setOutputMsg("~Login as " + nick);

    public void setOutputMsg(String message) {

    public void login() throws NickAlreadyInUseException, IOException, IrcException {
        setOutputMsg("~Connect to server " + server);

    protected void createConnect() throws NickAlreadyInUseException, IOException, IrcException {
        if (this.pass != null || this.pass.isEmpty()) {
            this.connect(server, port, pass);
        } else {

    protected void joinAllSubChannel() {
        sendRawLine("CAP REQ\r\n");     // NAMES, JOIN, PART & MODE
        sendRawLine("CAP REQ\r\n");         // PRIVMSG, USERSTATE, NOTICE &  GLOBALUSERSTATE

    public void joinChannel() {
        setOutputMsg("~Join channel " + channel);

// ##### CALL CLASS #####
try {
    IrcPircBot irc = new IrcPircBot();
} catch (Exception e) {
    System.out.println( e.getMessage() );

hm, this does not really help much tbh, since basically everything is hidden in the library calls. The only thing i can see, is that i can not see anything what would process any input, but i guess you have that somewhere? You should also make sure you are listening to Privmsg and not something else there.
Only alternative if you can not figure it out is using another library.

Another alternative would be sharing the whole code to debug it, but i guess thats no what you want to :smiley:

that is all…
each incomming message will be call the ‘setOutputMsg()’ method from the lib ‘PircBot’ (see class extends)

the class call is at the bottom of the scrollbox unter “##### CALL CLASS #####”
all other do the “PircBot” lib…

uhh…no xd actually pircbot calls “onMessage()” - nothing in your current code calls “setOutputMsg” except the one in “joinChannel”. Thats at least how all the pircbot examples work.

Edit: and by the way, for your own sake, remove those public attributes and write some proper getters and setters, it hurts. Or even better, pass them at the constructor

yesturday i’ll try the code at the bottom of this post… it lost at the same time like the other bot…
i dont know what it is but i think it’s a problem on my site… more on twitch site but dont know…

package testing;


public class irc  
    public String server = "";
    public String nick = "";
    public String login = "";
    public String channel = "";
    public String pass = "";

    private BufferedWriter writer = null;
    private BufferedReader reader = null;
    private String line = null;
    public void sendRawLine(String line) {
        try {
        } catch (IOException e) {}
    public void useDefault() {
        server = "";
        nick = "simple_bot";
        login = "simple_bot";
        channel = "#irchacks";    
    public boolean login() throws Exception {
        // Connect directly to the IRC server.
        System.out.println("try to login");
        Socket socket = new Socket(server, 6667);
        writer = new BufferedWriter( new OutputStreamWriter(socket.getOutputStream()) );
        reader = new BufferedReader( new InputStreamReader(socket.getInputStream()) );
        // Log on to the server.
        if (!pass.isEmpty()) {
            System.out.println("using pass: "+pass);
            sendRawLine("PASS " + pass + "\r\n");
        if (!nick.isEmpty()) {
            System.out.println("using nick: "+nick);
            sendRawLine("NICK " + nick + "\r\n");            

        if (!login.isEmpty()) {
            System.out.println("using login: "+login);
            sendRawLine("USER " + login + " 8 * : Java IRC Hacks Bot\r\n");
        // Read lines from the server until it tells us we have connected.
        line = null;
        while ((line = reader.readLine( )) != null) {
            System.out.println("loop " + line);
            if (line.indexOf("004") >= 0) {
                // We are now logged in.
                System.out.println("Login success.");
            } else if (line.indexOf("433") >= 0) {
                System.out.println("Nickname is already in use.");
                return false;
        return true;
    public void join() throws Exception {
        // Join the channel.
        if (!channel.isEmpty()) {
            sendRawLine("JOIN " + channel + "\r\n");        
            sendRawLine("CAP REQ\r\n");
            sendRawLine("CAP REQ\r\n");
            sendRawLine("CAP REQ\r\n");
    public void start() throws Exception {
        // Keep reading lines from the server.
        while ((line = reader.readLine( )) != null) {        
            if (line.trim().toUpperCase().startsWith("PING ")) {
                // We must respond to PINGs to avoid being disconnected.
                sendRawLine("PONG " + line.substring(5) + "\r\n");
            } else {
                // Print the raw line received by the bot.
    public void send(String message) throws Exception {
        if (!message.isEmpty()) {
            System.out.println( "Message: > PRIVMSG " + channel + " :" + message + "\r\n");
            sendRawLine("PRIVMSG " + channel + " :" + message + "\r\n");            
    public void leave() throws Exception {
        sendRawLine("PART " + channel + "\r\n");

alright, this code there should actually work fine. I mean you should still remove public attributes, but it should work. Can you probably clarify your Problem again? When exactly do you lose the connection?

it was just a short test script, that it the reason for the public attributes :wink:

I’ll hope i understand “probably clairify” right as “explain it again”.
The mailproblem is, that the script are get into the twitch chat und get the messages of the normal “public” chat, the whisper AND all notifications (user ban/timeout/purge, subscription, follow…).
All messages the script get but after a view minutes they get no public messages anymore (only whisper) and after a few minutes later, no whisper too. The script is still running (i’ll try it with a terminal output each 10 mins and this running all the time).

It has no spezial time, messages or else… sometimes the script run hours and sometimes only es few minutes…
At the biginning i thought it was because noone write into the chat but sometimes it happand if the chat is writing each second…
It isn’t at different times and on defferent computers and internet-connections (other router and other hoster).
I’ll try it with different accounts too but the problem is still there.

i dont have any idea >.<
i think this sounds like an excuse but could it be possible a problem on a part of twitch?

Sounds super weird tho. I have a few things running too related with chat and they never had an issue like that, so i still assume its something with your script. Can you actually send messages? For me this sounds either as an authentication or a timeout problem. Make sure you are correctly responding to Pings.

while i get messages i can send messages into the chat. on each ping i answer with a pong and that works fine…but i’ll look that sometimes i’ll dont get any ping but i cant send i pong to the server without a ping… or?