'Discord.py swear word filter
I'm making a discord.py bot with rewrite. I want to make an anti-swear word filter so that if someone swears in a message it will delete the message and send a message. I have a swear word file with all the words that I need.
This is the code that I have so far, but it doesn't work:
@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)
All help is appreciated!
Solution 1:[1]
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!")
await ctx.process_commands(message)
await ctx.process_commands(message) allows you to use commands after the on_message was used.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | polypoyo |
