Discord.py Auto-Filter Command

Viewed 196

so as you can see, i've recently joined stackoverflow. Mostly because i can find the answers. ok going to the point:

I've sort of what made a auto-filter command. It checks the file 'badwords.txt' that i have made for any swear words and if its in that file, the bot will delete the message and execute a message saying 'Don't do that!'. Here's the command:

with open('badwords.txt', 'r') as f:
global badwords  # You want to be able to access this throughout the code
words = f.read()
badwords = words.split()
async def on_message(ctx, message):
    msg = message.content
    for word in badwords:
        if word in msg:
            await message.delete()
            await ctx.send("Dont use that word!")
    await ctx.process_message(message)

My only question now is, how is it that you can make it so that if you swear more than three times, you'd get silenced for about an hour?

Thanks

1 Answers

I'm not sure if this is the best way of doing it, but maybe have a Dictionary that stores everybody's warnings.

warnings = {"user1":3,"user2",1}

Then, you can run a for loop that just checks if somebody has over 3, and does the appropriate actions.

Related