Search code examples
pythonbotsirc

Python Twitch IRC bot disconnecting after a period of time


So I have written a little bot that connects to twitch and is suppose to stay active till I close the script, but it seems after a elongated period of time the bot stops being connected to twitch and stops receiving anything. I think it is disconnecting, but I have no proof. Just the fact that it doesn't do anything after a while.

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
irc.send("PASS " + password + "\n")
irc.send("NICK " + name + "\n")
irc.send("JOIN " + channel + "\n")

def main():
while True:
    data = irc.recv(1204)
    data = data.strip('\r\n')
    sendUsr = data.split(" ")
    sendUsr = sendUsr[0]
    sendUsr = sendUsr.split("!")
    sendUsr = sendUsr[0]
    sendUsr = sendUsr.strip(":")


    print (data)

    if data.find('PING') != -1 :
        irc.send("PONG")

Solution

  • if data.find('PING') != -1 :
    irc.send("PONG")
    

    Needs to be changed to:

    if data.find('PING')
    irc.send("PONG :tmi.twitch.tv")
    

    Try doing that & it should work.