From fc519a13cc7554b1ea53495ab8592f7933893da0 Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:13:33 +0200 Subject: [PATCH] Fixed bot erroring if avatar doesn't exist --- bot/extensions/levelling/commands.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/extensions/levelling/commands.py b/bot/extensions/levelling/commands.py index 1e42b82e..3caefa29 100644 --- a/bot/extensions/levelling/commands.py +++ b/bot/extensions/levelling/commands.py @@ -115,6 +115,8 @@ async def on_message(self, message): def generate_rank_image(self, username: str, avatar_bytes: bytes, rank: int, level: int, xp: int, required_xp: int): img = Image.new("RGBA", (1000, 240)) logo = Image.open(BytesIO(avatar_bytes)).resize((200, 200)) + if logo.mode != "RGBA": + logo = logo.convert("RGBA") # Paste the default background image onto the new image img.paste(self.background, (0, 0)) @@ -282,7 +284,10 @@ async def rank(self, interaction: core.InteractionType, member: discord.Member = return await interaction.response.send_message("That user is not ranked yet...", ephemeral=True) # Fetch the user's avatar as bytes - avatar_bytes = await member.display_avatar.with_format("png").read() + try: + avatar_bytes = await member.display_avatar.with_format("png").read() + except discord.errors.NotFound: + avatar_bytes = await member.default_avatar.with_format("png").read() level = utils.get_level_for_xp(record.total_xp) prev_xp = utils.get_xp_for_level(level)