2016-06-29 7 views
-1

今、数時間の間、私はTwitchでストリームを再生するコードを使いこなしています。私は最後になった、とLiclipseでそれを実行しようとしたが、それは言う...ここPython - TypeError:バインドされていないメソッドtwitch_connect()は、インスタンス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); 

はこれに任意の修正はありますか?

+0

't = twitch.Twitch'だから' t'はクラスですか?それをインスタンス化することを意味しますか? 't = twitch.Twitch' **'() '** –

答えて

2

あなたがクラスオブジェクトでないインスタンスからtwitch_connectを呼んでいるが、twitch_connect方法は、最初の引数としてselfを取る(またはクラスのインスタンス):あなたは()を使用して、あなたのクラスをインスタンス化する必要があり

t = twitch.Twitch 

t = twitch.Twitch() 
t.twitch_connect(username, key) 

クラス自体からのみ静的メソッドとクラスメソッドを呼び出すことができます。しかしそれは別の話です。

+0

それは働いた。本当にありがとう! –

関連する問題