From 48cdea96ee30cc81198865b4c7646dbe8d71bf4d Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Fri, 4 May 2018 10:48:07 -0800 Subject: [PATCH] Add map location --- exts/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exts/utils.py b/exts/utils.py index 5d041ed..10caf53 100644 --- a/exts/utils.py +++ b/exts/utils.py @@ -606,11 +606,14 @@ class Utils: async with self.bot.aio_session.get( f'https://api.opencagedata.com/geocode/v1/json?q={location}&key={self.bot.geo_api}') as result: data = await result.json() - location_data = data['results'][0]['geometry'] - await msg.edit(content=f'Got Location. Please wait, Generating the image can take up to a minute.') - async with ctx.typing(): - await self.bot.loop.run_in_executor(self.bot.tpe, gen_image, location_data) - await msg.delete() + if data['total_results'] != 0: + location_data = data['results'][0]['geometry'] + await msg.edit(content=f'Got Location. Please wait, Generating the image can take up to a minute.') + async with ctx.typing(): + await self.bot.loop.run_in_executor(self.bot.tpe, gen_image, location_data) + await msg.delete() + else: + await msg.edit(content=f'I can\'t find any data for that location.\nPlease try again.') # TODO Create Help command