python - 我的文字过滤器阻止所有其他命令工作(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)
到事件的末尾将允许命令在被删除时运行。
解决方案
推荐阅读
- python - codejam round E 2019 中 #1 的运行时错误(已跳过测试集)
- templates - 从另一个模型翻译选择字段 - 模板网站 Odoo 11
- iteration - 如何有效且不平凡地实现迭代 Karatsuba?
- json - 如何使用powershell中的if条件在json文件中写入一个值?
- android - 如果满足条件则插入记录 房间数据库
- java - 我在 java 中使用 stringbuilder csv 创建 CSV 文件时遇到问题
- spring-mvc - Thymeleaf 访问嵌套对象
- sql-server - 使用 select 和 union 将值插入不同的数据库
- html - 选择元素的宽度不是 silbling、bootstrap 间距过冲
- linux - 从bash创建多个用户命名和编号的文件而不循环