From 3b8d8f6bbf303d09077436d7a487ec3a300feafb Mon Sep 17 00:00:00 2001 From: sgoudham Date: Mon, 24 Aug 2020 23:44:06 +0100 Subject: [PATCH] Using .get() for python dicts to avoid KeyErrors --- bot/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 58032025..1f29082e 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -225,10 +225,7 @@ class Bot(commands.Bot): def get_modmail(self, guild_id): """Returning the modmail system of the guild""" - if guild_id in self.modmail_cache: - return self.modmail_cache[guild_id] - else: - return None + return self.modmail_cache.get(guild_id) def update_modmail(self, guild_id, channel_id): """Update the modmail channel""" @@ -247,7 +244,7 @@ class Bot(commands.Bot): def get_roles_persist(self, guild_id): """Returning rolespersist value of the guild""" - return self.enso_cache[guild_id]["roles_persist"] + return self.enso_cache.get(guild_id)["roles_persist"] async def update_role_persist(self, guild_id, value): """Update the rolepersist value of the guild (Enabled or Disabled)""" @@ -319,8 +316,7 @@ class Bot(commands.Bot): def get_modlog_for_guild(self, guild_id): """Get the modlog channel of the guild that the user is in""" - channel = self.enso_cache[guild_id]["modlogs"] - return channel + return self.enso_cache.get(guild_id)["modlogs"] # --------------------------------------------!End ModLogs Section!-------------------------------------------------