一个命令中提供多个命令选项

时间:2015-10-05 19:10:29

标签: python

我正在使用像聊天机器人这样的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.")

1 个答案:

答案 0 :(得分: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.")

对于那个通知我的人我不能那样做,我道歉。当我查看它时,我误解了这一点。谢谢你让我知道。这是有效的更新代码。