现在几个小时,我一直在搞乱代码在Twitch上制作一个Twitch Plays流。我刚刚结束,并尝试在Liclipse中运行它,但它说......
TypeError:必须使用Twitch实例作为第一个参数调用未绑定方法twitch_connect()(改为使用str实例)
以下是完整代码:
#Define the imports
import twitch
import keypresser
import keyholder
t = twitch.Twitch
k = keypresser.Keypresser
seconds = 2
#Enter your twitch username and oauth-key below, and the app connects to twitch with the details.
#Your oauth-key can be generated at http://twitchapps.com/tmi/
username = "notgoingtoshow";
key = "notgoingtoshow";
t.twitch_connect(username, key)
#The main loop
while True:
#Check for new mesasages
new_messages = t.twitch_recieve_messages();
if not new_messages:
#No new messages...
continue
else:
for message in new_messages:
#Wuhu we got a message. Let's extract some details from it
msg = message['message'].lower()
username = message['username'].lower()
print(username + ": " + msg);
#This is where you change the keys that shall be pressed and listened to.
#The code below will simulate the key q if "q" is typed into twitch by someone
#.. the same thing with "w"
#Change this to make Twitch fit to your game!
if msg == "start": k.key_press("enter");
if msg == "b": keyholder.holdForSeconds(key, seconds);
if msg == "a": keyholder.holdForSeconds(key, seconds);
if msg == "up": keyholder.holdForSeconds(key, seconds);
if msg == "down": keyholder.holdForSeconds(key, seconds);
if msg == "left": keyholder.holdForSeconds(key, seconds);
if msg == "right": keyholder.holdForSeconds(key, seconds);
有没有解决这个问题?
答案 0 :(得分:2)
您从类对象调用twitch_connect
而不是实例,但twitch_connect
方法将self
(或类的实例)作为第一个参数:
t = twitch.Twitch
您应该使用()
实例化您的课程:
t = twitch.Twitch()
t.twitch_connect(username, key)
只能从类本身调用静态和类方法。但这是另一个不同的故事。