Thanks a lot!<br><br><div class="gmail_quote">On Sun, Sep 13, 2009 at 4:29 PM, MRAB <span dir="ltr"><<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Someone Something wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
I"m trying to write an IRC bot just for fun (in python of course). Here's my current code:<br>
<br>
  1 #!/usr/local/bin/python<br>
  2 import time<br>
  3 import socket<br>
  4<br>
  5 def message (x, channel,s):<br>
  6     y="PRIVMSG"+" "+ channel+" :"+x<br>
  7     s.send(y);<br></div>
  8 host="<a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> <<a href="http://irc.freenode.net" target="_blank">http://irc.freenode.net</a>>";<div class="im"><br>
  9 port=6667;<br>
 10 size=1024;<br>
 11 channel="#dhaivatrocks";<br>
 12 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);<br>
 13 s.connect((host,port));<br>
 14 s.send("NICK PoincareBot");<br>
 15 s.send("USER  PoincareBot 8 *  : Paul Mutton");<br>
 16 time.sleep(5);<br>
 17 s.send("JOIN #dhaivatrocks");<br>
 18 s.send(PRIVMSG #dhaivatrocks :Hello everybody!<br>
 19 while True:<br>
 20     pass;<br>
 21<br>
What I don't understand is that it doesn't display any messages or show a new message login on my IRC client. What's wrong with my code? <br>
</div></blockquote>
You probably need to put some sort of line ending on what you send, eg<br>
"\n" or "\r\n". Also, it's better to use 'sendall' insetad of 'send'.<br>
<br>
BTW, you don't need to put a semicolon on the end of the lines.<br><font color="#888888">
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>