几个小时以来,我一直在乱搞代码,让Twitch在Twitch上播放流媒体。我刚到最后,试着用李唇膏,但它说。。。你知道吗
TypeError: unbound method twitch_connect() must be called with Twitch instance as first argument (got str instance instead)
以下是完整代码:
#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);
有什么解决办法吗?你知道吗
从类对象调用
twitch_connect
不是实例,但是twitch_connect
方法将self
(或类的实例)作为第一个参数:应该使用
()
实例化类:只能从类本身调用静态方法和类方法。但这是另一个不同的故事。你知道吗
相关问题 更多 >
编程相关推荐