this is my code for my discord bot. I wanted to make the bot also deletes messages that contains bad words that has charactors (. , * / _ – and space character) the in between each letters of the words
import discord
from discord.ext import commands
from replit import db
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
automod = False
intents.messages = True
db = {}
def update_encouragements(encouraging_message):
if "encouragements" in db.keys():
encouragements = db["encouragements"]
encouragements.append(encouraging_message)
db["encouragements"] = encouragements
else:
db["encouragements"] = [encouraging_message]
def delete_encouragment(index):
encouragements = db["encouragements"]
if len(encouragements) > index:
del encouragements[index]
db["encouragements"] = encouragements
with open("bad_wrods.txt", "r") as t:
bad_words = t.read().splitlines()
def get_user_mention(mention):
if mention.startswith('<@') and mention.endswith('>'):
return client.get_user(mention[2:-1])
@client.event
async def on_message(message):
await client.process_commands(message)
global automod
if message.author == client.user:
return
if message.author.bot:
return
if automod:
if any(word in message.content.lower() for word in bad_words):
await message.delete()
await message.channel.send(
f"Nuh uh, {message.author.mention} Please do not use bad words."
)
if message.content.startswith("$automod-toggle") and message.author.id in [
822685628201697311, 998625868643565640
]:
if automod:
automod = False
else:
automod = True
await message.channel.send(
f"Automod is now {'enabled' if automod else 'disabled'}")
else:
is there anything that i can do to improve it?
I made a file that contains all the bad words, I tried to add make a copies of the words and put in the same file but i added space between the letters. it didnt work and also not effective because theres more than just the space character
John Hawking is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.