From 3ed4dcfbb4586d40e4e322f26c653ab65814c0ee Mon Sep 17 00:00:00 2001 From: Michal T Date: Mon, 13 Jan 2025 20:34:26 +0000 Subject: [PATCH] add exception handling --- ai_commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ai_commands.py b/ai_commands.py index ec91cf3..47a0f44 100644 --- a/ai_commands.py +++ b/ai_commands.py @@ -2,6 +2,7 @@ import logging import re import sys +import random from datetime import datetime from enum import Enum from typing import Optional @@ -373,8 +374,15 @@ class Events(commands.Cog): while (Path(temp_file_name)).exists(): temp_file_name = GRAPHICS_PATH + message.content + str(num) + ".png" num += 1 - with open(temp_file_name, "wb") as dalle_file: - dalle_file.write(response.content) + try: + with open(temp_file_name, "wb") as dalle_file: + dalle_file.write(response.content) + except OsError: + temp_file_name = "oserror.png" + with open(temp_file_name, "wb") as dalle_file: + dalle_file.write(response.content) + + self.logger.info("Koniec procedury obrazkowej.") fnord = discord.File( temp_file_name, spoiler=False, description=message.content