Discord Python Bot:在消息中搜索单词

时间:2021-03-15 14:27:05

标签: python discord bots

我的 Bot 有一些代码,如果有人写 uwu,它会与 owo 反应(f.e.)。 但我只能使用 if message.content.startswith("") 那么,是否可以在消息中搜索 uwu/owo (f.e. test uwu)?

这是一些代码:

        if message.content.startswith("UwU"):
            await message.channel.send("OwO")
        if message.content.startswith("OwO"):
            await message.channel.send("UwU")
        if message.content.startswith("uwu"):
            await message.channel.send("owo")
        if message.content.startswith("owo"):
            await message.channel.send("uwu")
        if message.content.startswith("Uwu"):
            await message.channel.send("Owo")
        if message.content.startswith("uwU"):
            await message.channel.send("owO")
        if message.content.startswith("Owo"):
            await message.channel.send("Uwu")
        if message.content.startswith("owO"):
            await message.channel.send("uwU")

1 个答案:

答案 0 :(得分:0)

您可以使用 substr in str。请参阅:https://stackabuse.com/python-check-if-string-contains-substring/

这将搜索整个字符串,而不仅仅是开头。例如:

if 'UwU' in str(message.content):
    await message.channel.send("OwO")
相关问题