From 343efba4d5daed0afde20e4b89c3b4f235b58917 Mon Sep 17 00:00:00 2001 From: PredaaA <46051820+PredaaA@users.noreply.github.com> Date: Sat, 19 Sep 2020 19:51:38 +0200 Subject: [PATCH] Handle aiohttp errors in `[p]set avatar` (#4437) * [Core comands] Handle aiohttp errors in set avatar * Update redbot/core/core_commands.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/core/core_commands.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index ba849a9e5..cc090ec9b 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1776,8 +1776,13 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): url = url[1:-1] async with aiohttp.ClientSession() as session: - async with session.get(url) as r: - data = await r.read() + try: + async with session.get(url) as r: + data = await r.read() + except aiohttp.InvalidURL: + return await ctx.send(_("That URL is invalid.")) + except aiohttp.ClientError: + return await ctx.send(_("Something went wrong while trying to get the image.")) else: await ctx.send_help() return