about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cogs/fun.py19
-rw-r--r--utils.py12
2 files changed, 18 insertions, 13 deletions
diff --git a/cogs/fun.py b/cogs/fun.py
index be58e08..898b132 100644
--- a/cogs/fun.py
+++ b/cogs/fun.py
@@ -32,11 +32,18 @@ class Fun(commands.Cog):
         await ctx.send("https://i.imgur.com/bOLCsd4.png")
 
     @commands.command(name="xkcd", brief="Gets XKCD comics.", help="Gets comics from https://xkcd.com, with the given number.")
-    async def xkcd(self, ctx, comic):
-        if int(comic) == 0:
-            await ctx.send("Invalid comic number!")
-        if int(comic) == 1 and int(comic) != "1":
-            await ctx.send("Invalid input!")
+    async def xkcd(self, ctx, comic=None):
+        if comic is None:
+            try:
+                response = requests.get('https://xkcd.com/info.0.json').json()
+                embed = discord.Embed(title=f"XKCD {response['num']}: {response['safe_title']}", colour=0xa37dca)
+                embed.set_image(url=response['img'])
+                embed.set_footer(text=response['alt'])
+                await ctx.send(embed=embed)
+            except:
+                raise commands.CommandInvokeError("Comic not found. The XKCD database may be down.")
+        elif int(comic) == 0:
+            raise commands.CommandInvokeError("Invalid comic number!")
         else:
             try:
                 response = requests.get(f'https://xkcd.com/{comic}/info.0.json').json()
@@ -45,7 +52,7 @@ class Fun(commands.Cog):
                 embed.set_footer(text=response['alt'])
                 await ctx.send(embed=embed)
             except:
-                await ctx.send("An error occurred. This is most likely because you entered a number for a comic that doesn't exist.")
+                raise commands.CommandInvokeError("Comic not found. The XKCD database may be down.")
 
 
 def setup(bot):
diff --git a/utils.py b/utils.py
index 0167c27..98fa8de 100644
--- a/utils.py
+++ b/utils.py
@@ -11,14 +11,12 @@ async def parse_error(ctx, error):
 
     if isinstance(error, commands.CommandNotFound):
         pass
-    elif isinstance(error, commands.MissingRequiredArgument):
-        await ctx.reply("Missing arguments! Make sure you've passed the correct ones.", mention_author=False)
-    elif isinstance(error, commands.MissingPermissions):
-        await ctx.reply("You do not have permission to do that!", mention_author=False)
-    elif isinstance(error, commands.BotMissingPermissions):
-        await ctx.reply("I don't have permission to do this! Make sure you've configured my role properly.", mention_author=False)
     else:
-        raise error
+        embed = discord.Embed(title="An error occurred!", color=0xc71a1a)
+        embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/798974923954978817.png?v=1")
+        embed.add_field(name=type(error).__name__, value=error, inline=False)
+        embed.set_footer(text="Tiny Potato Bot")
+        await ctx.send(embed=embed)
 
 class MyHelpCommand(commands.MinimalHelpCommand):
     async def send_pages(self):