tags:

views:

260

answers:

2
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 cant JOIN a channel, I get this Error. "451 JOIN :You have not registered"

+1  A: 

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.)

Mike Graham
thank you sir for your response
sourD
@sourD: Mike is right. I've done the irc-bot-with-sockets thing and it's very painful. I did it as a learning experience, but even as that it's not very valuable. Stick with the library
Daenyth
A: 

The particular channel you're trying to join requires you to be registered with the nickserv for that server. Try going on the server with a regular IRC client and creating a channel yourself, and tell the bot to join that.

Mike Trpcic
I still get the same error sir
sourD
I read the RFC and I get that cause the client isnt registered
sourD