Using asserts for error catching.

This commit is contained in:
alwayscompiling
2022-07-03 13:33:13 -04:00
parent ffeb8119f7
commit c046fa2c45
2 changed files with 12 additions and 14 deletions
+4 -4
View File
@@ -28,11 +28,11 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
highscore_channel_id = highscores_data["highscore_channel_id"]
print(f"Printing out highscores information in channel {highscore_channel_id}")
channel = self.bot.get_channel(highscore_channel_id)
if channel is None:
response = 'Registered Highscores channel does not exist or was never registered. \
error_response = 'Registered Highscores channel does not exist or was never registered. \
Register with "?register" command.'
await ctx.send(response)
return
assert channel is not None, await ctx.send(error_response)
for boss in highscores_config["bosses"]:
await highscore_message.send_highscore_message(channel, boss["boss"])
+8 -10
View File
@@ -26,18 +26,16 @@ class Score(commands.Cog, name="Score"):
verification_channel_id = highscores_data["verification_channel_id"]
channel = self.bot.get_channel(verification_channel_id)
if channel is None:
response = "Registered Verification channel does not exist or was never registered. \
error_response = "Registered Verification channel does not exist or was never registered. \
Contact server admins."
await ctx.send(response)
return
else:
verification_string = f"{ctx.author.display_name}:{boss_name}:{category}:{score}"
assert channel is not None, await ctx.send(error_response)
await channel.send(
content=verification_string,
files=[await attch.to_file() for attch in ctx.message.attachments],
)
verification_string = f"{ctx.author.display_name}:{boss_name}:{category}:{score}"
await channel.send(
content=verification_string,
files=[await attch.to_file() for attch in ctx.message.attachments],
)
# await highscore_manage.submit_score(self, ctx, boss_name, category, score)