my code is working. There is only one issue, which is that after calling any command, my on_message get called right after(which leads to some side effects)
async def delete_on_swear(message):
if not message:
return
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
try:
guild_id = message.guild.id
except AttributeError:
return
cursor.execute(f'SELECT word FROM badwords WHERE guild_id={guild_id}')
swears = [swear[0] for swear in cursor.fetchall()]
if not swears:
return
if bot.user == message.author:
return
for swearword in swears:
if not message.channel.is_nsfw() and is_substring(message.content.lower(), swearword):
await message.delete()
await message.author.create_dm()
await message.author.dm_channel.send(
f'Hi {message.author}, you sent a message containing the following word: {swearword}'
)
return```