机器人在说脏话后没有警告我
The bot doesn't warn me after saying a badwords
我试图在 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()
if any(b in bword for b in message.content.lower())
将遍历输入字符串中的每个 字符 而不是每个单词,因此它永远不会与您的任何坏词匹配。相反,通过用 message.content.lower().split(" ")
.
拆分来迭代单独的单词
我试图在 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()
if any(b in bword for b in message.content.lower())
将遍历输入字符串中的每个 字符 而不是每个单词,因此它永远不会与您的任何坏词匹配。相反,通过用 message.content.lower().split(" ")
.