aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2023-07-08 15:12:30 +0100
committerGravatar wookie184 <[email protected]>2023-07-08 15:12:30 +0100
commitd45356f94fa116539705057ca807f30d1f8d374a (patch)
treea90c9503af8cc151b05083b1688c6e01018f44ce /bot
parentType hint pagination as allowing float timeout (diff)
Handle snakes without images
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/fun/snakes/_snakes_cog.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/bot/exts/fun/snakes/_snakes_cog.py b/bot/exts/fun/snakes/_snakes_cog.py
index 2baacebc..f1a1cab9 100644
--- a/bot/exts/fun/snakes/_snakes_cog.py
+++ b/bot/exts/fun/snakes/_snakes_cog.py
@@ -989,21 +989,27 @@ class Snakes(Cog):
"""
# Get the snake data we need
if not name:
- name_obj = await self._get_snake_name()
- name = name_obj["scientific"]
- content = await self._get_snek(name)
+ for _ in range(3):
+ name_obj = await self._get_snake_name()
+ name = name_obj["scientific"]
+ content = await self._get_snek(name)
+ if len(content["image_list"]) > 0:
+ break
elif isinstance(name, dict):
content = name
-
else:
content = await self._get_snek(name)
+ try:
+ image_url = content["image_list"][0]
+ except IndexError:
+ await ctx.send("No images found for this snake.")
+ return
+
# Make the card
async with ctx.typing():
-
stream = BytesIO()
- image_url = content["image_list"][0]
async with self.bot.http_session.get(image_url, timeout=ClientTimeout(total=10)) as response:
stream.write(await response.read())