From 4f8f60660939bc3253186c009d7d63935361faf2 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Fri, 21 Sep 2018 17:03:19 -0500 Subject: [PATCH] Catch race condition --- cogs/images.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cogs/images.py b/cogs/images.py index 330482f..1742bda 100644 --- a/cogs/images.py +++ b/cogs/images.py @@ -3,7 +3,6 @@ import discord import random import re import math -import glob from bs4 import BeautifulSoup as bs from . import utils @@ -25,9 +24,12 @@ class Images: opts = {"format": "src"} result = await utils.request(url, attr='url', payload=opts) - image = await utils.download_image(result) - f = discord.File(image, filename=result.name) - await ctx.send(file=f) + try: + image = await utils.download_image(result) + f = discord.File(image, filename=result.name) + await ctx.send(file=f) + except (ValueError, AttributeError): + await ctx.send("I couldn't connect! Sorry no cats right now ;w;") @commands.command(aliases=['dog', 'rd']) @utils.custom_perms(send_messages=True)