Search code examples
pythonirc

IRC bot can't join channel


import socket

irc = 'irc.hack3r.com'
port = 6667
channel = '#chat'
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN #chat' + '\r\n')
data = ''
while True:
     data = sck.recv(4096)
     if data.find('PING') != -1:
        sck.send('PONG ' + data.split() [1] + '\r\n')
        print data

print sck.recv(4096)

When I connect to the server I can't JOIN a channel, I get this Error:

"451 JOIN :You have not registered"


Solution

  • It sounds like You are not registered and that is a requirement for joining that channel. You will have to register your nick and then identify before joining.

    Also, trying to make an irc bot with bare sockets is not a good idea. This code does not implement RFC 1459 to a useful level and it conflates the logic of your program with your networking. Consider using a networking library (Like Twisted. twisted.words has a great implementation of the IRC protocol) or writing code that is equivalent to one. (Hint, the former is easier and quicker and less bug prone.)