2015-10-05 47 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

请不要那样!作为答案添加您的解决方案。更改您的代码取决于帮助中心定义的无法执行的操作。请回复并添加您的代码作为答案。查看帮助中心的信息。谢谢。 –