prevent images from being too big for discord

This commit is contained in:
klemek
2020-04-29 12:36:10 +02:00
parent f99bfff3ed
commit 9f46e8b8f9
+3
View File
@@ -135,6 +135,9 @@ async def on_message(message: discord.Message):
else: else:
with tempfile.NamedTemporaryFile(delete=False) as output: with tempfile.NamedTemporaryFile(delete=False) as output:
img.save(output, format="JPEG") img.save(output, format="JPEG")
if os.stat(output.name).st_size > 8 * 1024 * 1024: # 8MB
await message.channel.send(":warning:\nOutput image is too big to be sent by discord")
else:
response = None response = None
meme_id = utils.sanitize_input(args[0]) meme_id = utils.sanitize_input(args[0])
if len(args) == 1 and meme_id not in ["image", "text"]: if len(args) == 1 and meme_id not in ["image", "text"]: