Search code examples
pythonsocketsirc

IRC BOT (python)


sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('PRIVMSG ' + 'NICKSERV' + 'ghost' + 'supaBOT' + 'htown')
sck.send('NICK supaBOT\r\n')
sck.send('PRIVMSG ' + 'NICKSERV' + 'IDENTIFY' + 'password')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN ' + " " + chan + '\r\n')

when I try running the script I get this error:

trix.gonullyourself.org 451 PRIVMSG  You have not registered
trix.gonullyourself.org 451 PRIVMSG  You have not registered
trix.gonullyourself.org 451 JOIN  You have not registered
: You

The nick supaBOT is registered on the server, but I dont know how to identify to the server, since the code above is not working.


Solution

  • Like Mike said, you're not sending the data you should be sending. You need to add the spaces there and you need : before final command arguments if they have spaces. Some of the lines are also missing '\r\n'.

    That is, the format for a PRIVMSG is: 'PRIVMSG nick :message with spaces\r\n'

    PRIVMSG only has two arguments, so you need to put the : there to indicate that the rest of the line is only one value which may include spaces.

    The reason you are getting "You have not registered" is because you must send USER and NICK commands before any other commands. And if the NICK command fails (nick collision), you must detect the error and try another one. Once you have sent a valid USER and NICK commands, some IRC networks also send you a PING, to which you must respond with a PONG before the server considers you "registered". After that you may use other commands.