【问题标题】:The code ignores the if conditions and runs the else statement [closed]代码忽略 if 条件并运行 else 语句 [关闭]
【发布时间】:2022-06-14 22:38:11
【问题描述】:

我的代码忽略了 if 条件这一事实存在问题。我的代码包含对命令 !game(游戏名称)的反应,但是。我的猫似乎在条件下忽略了游戏的给定名称,而是对命令不正确的事实做出反应(启动 else 块)。这是解释我想要做什么的代码:

    if message.lower().startswith("!game"):
        gamequestion = data.message.content[8:]
        if gamequestion.lower().startswith("tic tac toe"):
            sub_client.send_message(message=f"Im starting a first game, please wait...", chatId=chatId, replyTo=id)
        elif gamequestion.lower().startswith("rock paper scissors"):
            sub_client.send_message(message=f"Im starting a second game, please wait...", chatId=chatId, replyTo=id)
        else:
            sub_client.send_message(message=f"Incorrect name of game, try again!", chatId=chatId, replyTo=id)

【问题讨论】:

  • 什么是messagedata.message.content 是什么?我们需要minimal reproducible example 才有机会提供帮助。
  • 下断点,运行并检查变量,看看有什么与您的预期不同

标签: python bots


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-14
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
  • 2019-03-05
  • 2017-09-05
  • 2015-02-26
相关资源
最近更新 更多