2021-11-29

Discord.py SQLite3 Banned Word System - Issue

So, i tried making a banned word system using sqlite3, but i've ran into a issue and it doesn't error at all nor does it work

My code: ( yes i imported sqlite3 ) & the formatting is correct, its just the code it self


        @commands.Cog.listener()
        async def on_message(self, member):
            db = sqlite3.connect('.//SQL//bannedwords.sqlite')
            cursor = db.cursor()
            cursor.execute(f'SELECT msg FROM bannedwords WHERE guild_id = {message.guild.id}')
            result = cursor.fetchone()
            if result is None:

                return
            else:

                cursor.execute(f"SELECT msg FROM main WHERE guild_id = {member.guild.id}")
                result = cursor.fetchone()
                await message.author.delete()
                embed=discord.Embed(title="Blacklisted Word", description="Test")
                await message.send(embed=embed, delete_after=7.0)






    @commands.group(invoke_without_commands=True)
    async def add(self, ctx):
        return







    @add.command()
    async def word(self, ctx, channel:discord.TextChannel):
        if ctx.message.author.guild_permissions.administrator:
            db = sqlite3.connect('.//SQL//bannedwords.sqlite')
            cursor = db.cursor()
            cursor.execute(f'SELECT msg FROM bannedwords WHERE guild_id = {ctx.guild.id}')
            result = cursor.fetchone()
            if result is None:
                sql = ("INSERT INTO bannedwords(guild_id, msg) VALUES(?,?)")
                val = (ctx.guild.id, msg)
                await ctx.send(f"h")
            elif result is not None:
                sql = ("UPDATE bannedwords SET msg = ? WHERE guild_id = ?")
                val = (msg, ctx.guild.id)
                await ctx.send(f"added")
            cursor.execute(sql, val)
            db.commit()
            cursor.close()
            db.close()

I am aware that i put a text channel, but i don't think thats the only issue - or rather i'm not too sure on what do i replace it with for it to detect messages that are in the msg column



from Recent Questions - Stack Overflow https://ift.tt/3cX7rUx
https://ift.tt/eA8V8J

No comments:

Post a Comment