【发布时间】:2022-08-11 19:44:56
【问题描述】:
if [\"a\", \"e\"] in msg.content:
我尝试在 on_message 中搜索列表中的任何单词是否在消息内容中,但我收到此错误
TypeError: \'in <string>\' requires string as left operand, not list
-
in期望左侧有一个字符串,而不是字符串列表。
标签: discord.py nextcord
if [\"a\", \"e\"] in msg.content:
我尝试在 on_message 中搜索列表中的任何单词是否在消息内容中,但我收到此错误
TypeError: \'in <string>\' requires string as left operand, not list
in 期望左侧有一个字符串,而不是字符串列表。
标签: discord.py nextcord
正如错误所暗示的,左侧应该有一个字符串。从您的示例中,我不清楚您是否要检查所有字符串是否都在 msg.content 中,或者是否其中任何一个都在 msg.content 中。所以这里有两种情况:
if all(_ in msg.content for _ in ["a", "e"]):
或者
if any(_ in msg.content for _ in ["a", "e"]):
【讨论】: