Reputation: 62
After adding an on_message, the rest of my commands stop working. I've seen this question be asked before, I tried adding await client.process_commands(message)
, that fixed it, but after changing a few things around, it stopped working. This is supposed to detect blacklisted words, delete them, then delete the message after.
@client.event
async def on_message(message):
if message.author.bot: return
message.content = message.content.lower().replace(' ', '')
if "example1" in message.content or "example2" in message.content or "example3" in message.content or "example4" in message.content:
await message.delete()
await message.channel.send(f"{message.author.mention} That word is not allowed!", delete_after=1.5)
await message.delete()
await client.process_commands(message)
Upvotes: 0
Views: 875
Reputation: 528
You're modifying message.content
before you pass it to process_commands
; specifically, you're removing all the spaces. Of course none of your command names are going to be matched against a giant, single-word string.
Don't directly modify message.content
. Since you're checking with in
, you don't even need to remove the spaces. Your conditional can also be simplified.
Moreover, as effprime pointed out, if you're going to delete offending messages it doesn't make sense to try to process any commands from them. So you need to either delete the message or process commands from it, not both.
bad_words = ['example1', 'example2', 'example3', 'example4']
if any(word in message.content.lower() for word in bad_words):
await message.delete()
...
else:
await client.process_commands(message)
Upvotes: 3