Using .get() for python dicts to avoid KeyErrors

pull/8/head
sgoudham 4 years ago
parent b2dc7a168b
commit 3b8d8f6bbf

@ -225,10 +225,7 @@ class Bot(commands.Bot):
def get_modmail(self, guild_id): def get_modmail(self, guild_id):
"""Returning the modmail system of the guild""" """Returning the modmail system of the guild"""
if guild_id in self.modmail_cache: return self.modmail_cache.get(guild_id)
return self.modmail_cache[guild_id]
else:
return None
def update_modmail(self, guild_id, channel_id): def update_modmail(self, guild_id, channel_id):
"""Update the modmail channel""" """Update the modmail channel"""
@ -247,7 +244,7 @@ class Bot(commands.Bot):
def get_roles_persist(self, guild_id): def get_roles_persist(self, guild_id):
"""Returning rolespersist value of the guild""" """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): async def update_role_persist(self, guild_id, value):
"""Update the rolepersist value of the guild (Enabled or Disabled)""" """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): def get_modlog_for_guild(self, guild_id):
"""Get the modlog channel of the guild that the user is in""" """Get the modlog channel of the guild that the user is in"""
channel = self.enso_cache[guild_id]["modlogs"] return self.enso_cache.get(guild_id)["modlogs"]
return channel
# --------------------------------------------!End ModLogs Section!------------------------------------------------- # --------------------------------------------!End ModLogs Section!-------------------------------------------------

Loading…
Cancel
Save