From 8a2d86870c5bad09b7741cfe22f200f3afdca0c6 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sun, 2 Aug 2020 18:46:15 +0200 Subject: [PATCH] Remove warns from database when leave a guild --- extensions/warn.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/extensions/warn.py b/extensions/warn.py index de74ad4..b604d7e 100644 --- a/extensions/warn.py +++ b/extensions/warn.py @@ -1,6 +1,6 @@ import re -from discord import Embed, Forbidden, Member +from discord import Embed, Forbidden, Member, Guild from discord.ext import commands from discord.ext.commands import BadArgument @@ -105,6 +105,14 @@ class Warn(commands.Cog): await ctx.send(embed=embed) + @commands.Cog.listener() + async def on_guild_remove(self, guild: Guild): + s = db.Session() + for w in s.query(db.Warn).filter(db.Warn.guild == guild.id).all(): + s.delete(w) + s.commit() + s.close() + def setup(bot): logger.info(f"Loading...")