【问题标题】:The bot doesn't warn me after saying a badwords机器人在说坏话后没有警告我
【发布时间】:2020-11-29 05:47:44
【问题描述】:

我试图在 discord.py 上使用 sqlite3 制作一个坏词过滤器,尽管我发誓我的数据库中列出的单词,但它不知何故没有向我发送任何内容

    @commands.Cog.listener()
    async def on_message(self, message):
        if not message.author.bot:
            db = sqlite3.connect('main.db')
            cursor = db.cursor()
            cursor.execute(f"SELECT text FROM badwords WHERE guild_id = {message.guild.id}")
            result = cursor.fetchall()
            if result is None:
                return
            if result is not None:
                bword = [x[0] for x in result]
                if any(b in bword for b in message.content.lower()):
                    await message.channel.send("plz no swear my bot is noob")
                cursor.close()
                db.close()

【问题讨论】:

    标签: sqlite discord discord.py discord.py-rewrite


    【解决方案1】:

    if any(b in bword for b in message.content.lower()) 将遍历输入字符串中的每个 字符 而不是每个单词,因此它永远不会与您的任何坏词匹配。相反,通过将其拆分为 message.content.lower().split(" ") 来迭代单独的单词。

    【讨论】:

      猜你喜欢
      • 2018-12-13
      • 2015-02-14
      • 2021-05-20
      • 2020-09-01
      • 2019-01-19
      • 2020-09-12
      • 2023-02-17
      • 1970-01-01
      • 2020-07-17
      相关资源
      最近更新 更多