Python 3.x 如何使我的聊天过滤块绕过符号、大写和空格??(discord.py重写)
很长一段时间以来,我一直在开发一个聊天过滤器,它可以屏蔽很多东西。我试过两种方法,但都没有成功。 我想到的第一段代码是:Python 3.x 如何使我的聊天过滤块绕过符号、大写和空格??(discord.py重写),python-3.x,discord.py,Python 3.x,Discord.py,很长一段时间以来,我一直在开发一个聊天过滤器,它可以屏蔽很多东西。我试过两种方法,但都没有成功。 我想到的第一段代码是: with open('badwords.txt', 'r'): bad_words = file.read().splitlines() @client.event async def on_message(message): for word in bad_words: if word in message.content.split(&q
with open('badwords.txt', 'r'):
bad_words = file.read().splitlines()
@client.event
async def on_message(message):
for word in bad_words:
if word in message.content.split(" "):
await message.channel.send("Please don't send that word here.")
await message.delete()
break
但这只会阻塞文字,因此我必须添加所有旁路,所以这对我不起作用。然后我尝试了一个正则表达式,它工作了一段时间,直到我发现它阻塞了没有坏话的东西。
这是我的正则表达式:
with open('badwords.txt', 'r'):
blacklist = file.read().split('\n')
@client.event
async def on_message(message):
for word in blacklist:
regex_match_true = re.compile(fr"[{symbols}]*".join(list(word)), re.IGNORECASE)
regex_match_none = re.compile(fr"([{letters}]+{word})|({word}[{letters}]+)", re.IGNORECASE)
if regex_match_true.search(message.content) and regex_match_none.search(message.content) is None:
await message.channel.send("Please don't send that word here.")
await message.delete()
break
我一直在寻找更多的解决方案,但什么都没有找到。有人能帮我吗