from socket import * s = socket(AF_INET,SOCK_STREAM) s.connect(("irc.freenode.net",6667)) user = "BOTUSER" channel = "#mtmt" message = "Hello!" s.send("USER "+user+" "+user+" "+user+" "+user+"\n") s.send("NICK "+user+"\n") s.send("JOIN "+channel+"\n") while 1: success = True try: fi = open("message.txt", 'r') except: success = False # File could not be opened if success: s.write("PRIVMSG " + channel + " :" + fi.read() + "\n") # Read message from message.txt and msg it to the channel fi.close() msg = s.recv(1024) print (msg)