added error message

This commit is contained in:
phixxy 2024-01-22 16:18:12 -08:00
parent 4b928145d0
commit 7ea905be7e

View file

@ -28,6 +28,7 @@ class Waifu(commands.Cog):
async def get_anime_from_img(self, img_url): async def get_anime_from_img(self, img_url):
async with self.bot.http_session.get(f"https://api.trace.moe/search?anilistInfo&url={img_url}") as resp: async with self.bot.http_session.get(f"https://api.trace.moe/search?anilistInfo&url={img_url}") as resp:
resp_data = await resp.json() resp_data = await resp.json()
print(resp_data)
title = resp_data["result"][0]["anilist"]["title"] title = resp_data["result"][0]["anilist"]["title"]
video = resp_data["result"][0]["video"] video = resp_data["result"][0]["video"]
return title, video return title, video
@ -42,7 +43,10 @@ class Waifu(commands.Cog):
except: except:
await ctx.send("No image linked or attached.") await ctx.send("No image linked or attached.")
return return
try:
titles, video = await self.get_anime_from_img(file_url) titles, video = await self.get_anime_from_img(file_url)
except:
ctx.send("An error occurred. Try again by saving and uploading the image.")
message = "" message = ""
for key in titles: for key in titles:
message += f"{key}: {titles[key]}\n" message += f"{key}: {titles[key]}\n"