EduCodes
EduCodes

Reputation: 23

TypeError: does not support the buffer interface Twitch IRC Chat Bot

To start off, I couldn't find an answer anywhere. Im not sure if its something I need to import or if its just poorly done code. In a nut shell, with this project im going to make a better twitch follower notifier with SMS messages, and a lot of other things.

Edit: The whole crash log is as follows:

line 16 in <module>
irc.send('PASS ' + password + '\r\n')
TypeError: Does not support the buffer interface

Also, I had to repeatedly double click the file to get this, so I'm sorry if its a little bit off. I couldn't get a coded crash log thing to work.

import socket #imports module allowing connection to IRC
import threading #imports module allowing timing functions

bot_owner = 'BetterFollowerBot'
nick = 'BetterFollowerBot'
channel = '#BetterFollowerBot'
server = 'irc.twitch.tv'
password = '~Took This Out~'

queue = 0 #sets variable for anti-spam queue functionality

irc = socket.socket()
irc.connect((server, 6667)) #connects to the server

#sends variables for connection to twitch chat
irc.send('PASS ' + password + '\r\n')
irc.send('USER ' + nick + ' 0 * :' + bot_owner + '\r\n')
irc.send('NICK ' + nick + '\r\n')
irc.send('JOIN ' + channel + '\r\n') 

def message(msg): #function for sending messages to the IRC chat
    global queue
    queue = queue + 1
    print (queue)
    if queue < 20: #ensures does not send >20 msgs per 30 seconds.
        irc.send('PRIVMSG ' + channel + ' :' + msg + '\r\n')
    else:
        print ('Message deleted')

def queuetimer(): #function for resetting the queue every 30 seconds
    global queue
    print ('queue reset')
    queue = 0
    threading.Timer(30,queuetimer).start()
queuetimer()

while True:
    data = irc.recv(1204) #gets output from IRC server
    user = data.split(':')[1]
    user = user.split('!')[0] #determines the sender of the messages
    print (data)

    if data.find('PING') != -1:
        irc.send(data.replace('PING', 'PONG')) #responds to PINGS from the server
    if data.find('!test') != -1: #!test command
        message('Hi')

Upvotes: 2

Views: 555

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180441

You need to convert to bytes:

irc.send(bytes("PASS {}\r\n".format(password), 'utf-8'))
irc.send(bytes('USER {} 0 * :{}\r\n'.format(nick,bot_owner),"utf-8"))
irc.send(bytes('NICK {}\r\n'.format(nick),"utf-8"))
irc.send(bytes('JOIN {}\r\n'.format(channel),"utf-8"))

And decode:

recv(1204).decode("utf-8")

Upvotes: 2

Related Questions