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