2015-10-05 59 views
1

我正在開發一個像聊天機器人這樣的IRC,用於連接到IP.Board論壇,它將用於遊戲和搞亂遊戲。我有一個命令問題,它真的開始誤導我,因爲它開始工作,然後開始拋出由函數的elif部分引起的錯誤。昨晚我測試,它似乎工作得很好,但是當我今天早上啓動了做一些更多的工作就開始引發錯誤:一個命令中有多個命令選項

user, newItem = args.split("with", 1) 
    ERROR requires 2 arguments but only one was specified 

我已經包含下面的腳本代碼。

編輯:我固定的問題和更新,下面的代碼,以幫助他人

if cmd == "slap": 
     try: 
      if args == user.lower(): 
        group.sendPost("-slaps "+args+" with "+random.choice(Items)+"-") 
      else: 
        user, newItem = args.split("with", 1) 
        group.sendPost("-Slaps "+user+" with "+newItem+"-") 
        f = open("DictItems", "a") 
        f.write("" + newItem + '\n') 
        f.close() 
     except: 
        print("Slap Command Errored with NewItem") 
        group.sendPost("I'm sorry, that command seems to be broken. I have notified the staff.") 
        self.sendPM(Yusei, "I'm sorry to inform but the slap command has failed with an error defining the newItem. Please look into it. Thank you.") 
+0

您的寫入行在開始時不需要初始'「」''。這是一個空字符串。此外,我不確定這一點,但你有兩個分裂的理由嗎?即如果你有''foo'',它會拋出一個錯誤,但它不是你指定的那個。 – SirParselot

+0

你能提供導致錯誤的輸入嗎? – SirParselot

+0

執行該命令的命令是.slap [insertnamehere]與[randomitem]或.slap [insertnamehere]。另外,我將空字符串放在那裏以啓動輸入,但如果不需要,我可以刪除它。 – LordYusei

回答

0
if cmd == "slap": 
     try: 
      if args in whitelist: 
        group.sendPost("-slaps "+args+" with "+random.choice(Items)+"-") 
      else: 
        user, newItem = args.split("with", 1) 
        group.sendPost("-Slaps "+user+" with "+newItem+"-") 
        f = open("DictItems", "a") 
        f.write("" + newItem + '\n') 
        f.close() 
     except: 
        print("Slap Command Errored with NewItem") 
        group.sendPost("I'm sorry, that command seems to be broken. I have notified the staff.") 
        self.sendPM(Yusei, "I'm sorry to inform but the slap command has failed with an error defining the newItem. Please look into it. Thank you.") 

另外要taht通知我,我不能這樣做,我道歉的人。當我查看它時,我誤解了這一點。謝謝你讓我知道。這是更新後的代碼。

+0

請不要那樣!作爲答案添加您的解決方案。更改您的代碼取決於幫助中心定義的無法執行的操作。請回復並添加您的代碼作爲答案。查看幫助中心的信息。謝謝。 –