From 33d253bdfb33324996f7fdcc64502d1147c4085c Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 4 Sep 2023 13:14:25 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(ChatProcess.py):=20handle=20?= =?UTF-8?q?APIError=20separately=20in=20error=20handling=20logic=20to=20pr?= =?UTF-8?q?ovide=20a=20specific=20error=20message=20when=20OpenAI=20API=20?= =?UTF-8?q?is=20not=20working=20=F0=9F=90=9B=20fix(ChatProcess.py):=20impr?= =?UTF-8?q?ove=20error=20handling=20logic=20to=20provide=20a=20more=20info?= =?UTF-8?q?rmative=20error=20message=20when=20an=20error=20occurs=20while?= =?UTF-8?q?=20processing=20a=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ChatProcess.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ChatProcess.py b/src/ChatProcess.py index 6b38199..c142b37 100644 --- a/src/ChatProcess.py +++ b/src/ChatProcess.py @@ -5,6 +5,7 @@ import discord import datetime import json +from openai.error import APIError from src.utils.misc import moderate from src.utils.variousclasses import models, characters from src.guild import Guild @@ -209,13 +210,19 @@ class Chat: self.message.remove_reaction("🤔", self.message.guild.me) except: pass - await self.message.channel.send( - f"""An error occured while processing your message, we are sorry about that. Please check your settings and try again later. If the issue persists, please join uor discord server here: https://discord.gg/pB6hXtUeDv and send the following logs: -``` -{e} -```""", - delete_after=4, - ) + if isinstance(e, APIError): + await self.message.channel.send( + "Due to OpenAI not doing their work, I can unfortunately not answer right now. Do retry soon!", + delete_after=5, + ) + else: + await self.message.channel.send( + f"""An error occured while processing your message, we are sorry about that. Please check your settings and try again later. If the issue persists, please join uor discord server here: https://discord.gg/pB6hXtUeDv and send the following logs: + ``` + {e} + ```""", + delete_after=4, + ) try: await self.message.add_reaction("😞") except: