From dbb02c0892eddcddd41ad23583a15c72898effac Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 4 Oct 2023 09:42:22 -0400 Subject: [PATCH] fix(moderation): fixed the connect method --- moderation/moderation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 142dea7..9bc6a8d 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -32,8 +32,11 @@ class Moderation(commands.Cog): logging.fatal("Failed to create tables, due to MySQL connection configuration being unset.") return guilds: list[discord.Guild] = self.bot.guilds - for guild in guilds: - await self.create_guild_table(guild) + try: + for guild in guilds: + await self.create_guild_table(guild) + except ConnectionRefusedError: + return @commands.Cog.listener('on_guild_join') async def db_generate_guild_join(self, guild: discord.Guild): @@ -47,7 +50,10 @@ class Moderation(commands.Cog): if conf: logging.fatal("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id) return - await self.create_guild_table(guild) + try: + await self.create_guild_table(guild) + except ConnectionRefusedError: + return async def connect(self): """Connects to the MySQL database, and returns a connection object.""" @@ -64,7 +70,7 @@ class Moderation(commands.Cog): host=await self.config.mysql_address(), user=await self.config.mysql_user(), password=await self.config.mysql_password(), - database=await self.config.mysql_db() + database=await self.config.mysql_database() ) return connection except mysql.connector.ProgrammingError as e: