Skip to content

Commit

Permalink
Fixed bot erroring if avatar doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
FirePlank committed Nov 25, 2023
1 parent 35891d9 commit fc519a1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bot/extensions/levelling/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fc519a1

Please sign in to comment.