aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Akarys42 <[email protected]>2019-11-27 18:41:57 +0100
committerGravatar Akarys42 <[email protected]>2019-11-27 18:41:57 +0100
commit4a1ca965e2b83ea8690b3d7408464c8205432482 (patch)
treede44d8e20a98b36c08a43aacf9a6f47022fe6ffa
parentMove attachments re-uploading to DeletionContext.add() (diff)
Add try/except for attachment saving
-rw-r--r--bot/cogs/antispam.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py
index 8009c9d42..3118e0a42 100644
--- a/bot/cogs/antispam.py
+++ b/bot/cogs/antispam.py
@@ -7,7 +7,7 @@ from io import BytesIO
from operator import itemgetter
from typing import Dict, Iterable, List, Set
-from discord import Colour, File, Member, Message, NotFound, Object, TextChannel
+from discord import Colour, File, HTTPException, Member, Message, NotFound, Object, TextChannel
from discord.ext.commands import Bot, Cog
from bot import rules
@@ -274,10 +274,13 @@ async def reupload_attachments(
channel = bot.get_channel(channel_id)
out = []
for attachment in message.attachments:
- with BytesIO() as buffer:
- await attachment.save(buffer, use_cached=True)
- reupload: Message = await channel.send(file=File(buffer, filename=attachment.filename))
- out.append(reupload.attachments[0].url)
+ try:
+ with BytesIO() as buffer:
+ await attachment.save(buffer, use_cached=True)
+ reupload: Message = await channel.send(file=File(buffer, filename=attachment.filename))
+ out.append(reupload.attachments[0].url)
+ except (HTTPException, NotFound):
+ log.warning(f"Tried to re-upload attchment {attachment.id}, but it has failed.")
return out