【发布时间】: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)
【问题讨论】:
-
什么是
message?data.message.content是什么?我们需要minimal reproducible example 才有机会提供帮助。 -
下断点,运行并检查变量,看看有什么与您的预期不同