Python connect to IRC function - must be integer
Question: I made a basic IRC bot that would join a certain channel and say a defined
phrase, as part of learning Python. However, are there changes in the latest
version of Python?

    
    
    import socket
    
    nick = 'TigerBot'
    passdwd = '*****'
    port = '6667'
    net = 'irc.snoonet.org'
    chan = '#WritingPrompts'
    
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Was ist da IRC Socket? 
    
    sock.connect ((net, port)) # Open server connection
    
    irc.recv (4096) # Buffer setup
    irc.send('nick ' + nick + '\r\n') # What is your name?
    irc.send('USER AffixBot AffixBot AffixBot :Affix IRC\r\n') #Send User Info to the server
    irc.send('JOIN ' + chan + '\r\n') # Join the pre defined channel
    irc.send('PRIVMSG ' + chan + ' :Hello.\r\n') #Send a Message to the  channel
    
    while True: #While Connection is Active
        data = irc.recv (4096) #Make Data the Receive Buffer
        if data.find('PING') != -1: # If PING
         irc.send('PONG ' + data.split()[1] + '\r\n') # Then PONG
    

Line 11 is the problem - apparently, what I've got down as a string needs to
be an integer. How can I go about this?


Answer: Change your definition of port to be an integer.

    
    
    port = 6667
    

not

    
    
    port = '6667'
    

In general, if you have an existing string value that needs to be an int for a
specific call, you can cast by calling `int(str)`, which will return the value
of str as an integer or raise a `ValueError` if it can't cast.

