I am making a Discord bot that blocks swear words. It can be bypassed by using underscores and/or other symbols attached to the swear word.
How do I get the script to still block these words but not delete characters in general?
Here is my code:
import discord
import random
import string
from discord.ext import commands
client = commands.Bot(command_prefix = 'as-')
with open("badwords2.txt") as file:
bad_words = file.read().splitlines()
def check_if_allowed(text):
allowed_characters = string.ascii_uppercase + string.ascii_lowercase
if character not in allowed_characters:
return False
return True
@client.event
async def on_message(message):
for bad_word in bad_words:
if bad_word in message.content.lower().split(" "):
t = discord.Embed(color=0x039e00, title="Message Removed", description=":x: Please do not swear. Swearing can result in a mute or ban.")
t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
await message.channel.send(embed=t)
await message.delete()
return
if not check_if_allowed(message.content):
t = discord.Embed(color=0x039e00, title="Message Removed", description=":x: Please do not swear. Swearing can result in a mute or ban.")
t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
await message.channel.send(embed=t)
await message.delete()
return
client.run('TOKEN')