Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使我的聊天过滤块绕过符号、大写和空格??(discord.py重写)_Python 3.x_Discord.py - Fatal编程技术网

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
我一直在寻找更多的解决方案,但什么都没有找到。有人能帮我吗