首页 > 解决方案 > 我的文字过滤器阻止所有其他命令工作(discord.py)

问题描述

我有一个单词过滤器,它工作得非常好,但是当我尝试使用命令时,我无法使用它,因为如果正在使用过滤器(在主文件)命令是这样的。

#Censor/Filter
with open("badwords.txt") as file: # badwords.txt contains one phrase per line
    bad_words = [bad_word.strip().lower() for bad_word in file.readlines()] # Reading

@bot.event
async def on_message(message):
    if any(bad_word in message.content.lower() for bad_word in bad_words):
        channel = bot.get_channel(859495659639668757)
        await channel.send("{}, your message has been censored.".format(message.author.mention))
        await message.delete()

我可以做些什么来使命令正常工作吗?

添加 await bot.process_commands(message)到事件的末尾将允许命令在被删除时运行。

标签: pythondiscorddiscord.py

解决方案


推荐阅读