From f1f01428b44105d2919afb0c9b5b540d98ab93c7 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 27 Apr 2023 08:29:30 -0700 Subject: [PATCH] error handling if the ship isnt found --- app/star_citizen.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/star_citizen.py b/app/star_citizen.py index baa9e7d0..75d0aaa6 100644 --- a/app/star_citizen.py +++ b/app/star_citizen.py @@ -9,8 +9,17 @@ async def get_ship(ship_name): base_url = "https://robertspaceindustries.com" wiki_url = "https://starcitizen.tools/" - ship = await Ship(name=ship_name).get_ships_pages_async() - ship = ship[0] + try: + ship = await Ship(name=ship_name).get_ships_pages_async() + ship = ship[0] + except IndexError: + embed = discord.Embed(description="❌", color=discord.Color.red(), type="rich") + embed.add_field( + name="**Could not find that ship**", value="You gave me %s. Did you spell it right? (Its also possible my shitty code isnt working right)" % ship_name, inline=True + ) + return embed + + # prints for debug # pp = pprint.PrettyPrinter(indent=4) # pp.pprint(ship)