TypeError:'in <string>'需要将字符串作为左操作数,而不是列表(discord.py)

时间:2020-02-01 10:20:43

标签: python discord

试图使基本的聊天机器人不和谐。

现在,我知道为什么我的代码有错误,还有另一个问题几乎与我的相同。但是,我尝试了另一种解决方案,但不幸的是,该解决方案在我的情况下不起作用。所以谁知道我该如何解决此功能?

@client.event
async def on_message(message):
r1 = ['Hello!', 'Hi!', 'Greetings!']
r2 = ['I am feeling excellent!' 'Working today feels great!']
if client.user.id != message.author.id:
    if client.user.mentioned_in(message) and message.mention_everyone is False:
        if 'help' in message.content.lower():
            await message.channel.send(
            'How may I assist you?')
        else:
            await message.add_reaction('?')  # :eyes:
    if ['hi', 'hello'] in message.content.lower():
        await message.channel.send(f'{random.choice(r1)}')

这会给我类型错误,因为我在message.content.lower()之前有一个列表


    if message.content.lower() in ['How are you?', 'How are you doing?', 'How are you feeling?']:
        await message.channel.send(f'{random.choice(r2)}')

虽然这只会使漫游器无响应(不希望它正常工作,但无论如何还是尝试过),甚至不会在控制台中报告任何错误。

再次,我感到我错过了一些确实很明显的事情,但我无法弄清楚。任何帮助表示赞赏。另外,我知道我可以将列表分开并单独处理每个单词,但这会使它不必要地混乱。

1 个答案:

答案 0 :(得分:0)

可以通过以下方式解决(在['hi','hello']中我的message.content.lower()。split()中的i) 感谢您的帮助!

相关问题