【问题标题】:TypeError: 'in <string>' requires string as left operand, not list | discord.pyTypeError: \'in <string>\' 需要字符串作为左操作数,而不是列表 |不和谐.py
【发布时间】:2022-08-11 19:44:56
【问题描述】:
if [\"a\", \"e\"] in msg.content:

我尝试在 on_message 中搜索列表中的任何单词是否在消息内容中,但我收到此错误

TypeError: \'in <string>\' requires string as left operand, not list

标签: discord.py nextcord


【解决方案1】:

正如错误所暗示的,左侧应该有一个字符串。从您的示例中,我不清楚您是否要检查所有字符串是否都在 msg.content 中,或者是否其中任何一个都在 msg.content 中。所以这里有两种情况:

if all(_ in msg.content for _ in ["a", "e"]):

或者

if any(_ in msg.content for _ in ["a", "e"]):

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 2021-07-29
    相关资源
    最近更新 更多