【发布时间】:2020-09-17 07:04:54
【问题描述】:
我正在制作一个带有重写功能的 discord.py 机器人。我想制作一个反脏话过滤器,这样如果有人在消息中发誓,它将删除消息并发送消息。我有一个包含我需要的所有单词的 swear word 文件。
这是我到目前为止的代码,但它不起作用:
@client.event
async def on_message(ctx, message):
msg = message.content
with open('badWords.txt') as BadWords:
if msg in BadWords.read():
await message.delete()
await ctx.send("Dont use that word!")
else:
await ctx.process_commands(message)
感谢所有帮助!
【问题讨论】:
标签: python python-3.x file filter discord.py