【问题标题】:Discord Python Bot: Searching for words in a MessageDiscord Python Bot:在消息中搜索单词
【发布时间】:2023-04-02 11:10:01
【问题描述】:

我的 Bot 有一个小代码,如果有人写 uwu,它会与 owo 做出反应(例如)。 但我只能使用 if message.content.startswith("") 那么,是否可以在消息中搜索 uwu/owo(例如 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")

【问题讨论】:

    标签: python discord bots


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-03-23
      • 2021-03-27
      • 2021-10-30
      • 2018-07-07
      • 2019-07-04
      • 2020-08-25
      • 2021-08-12
      • 2022-08-19
      • 2021-08-27
      相关资源
      最近更新 更多