Просмотр исходного кода

Corriger la fermeture du bot et ses logs

Andy Esnard 1 день назад
Родитель
Сommit
f363989dd1
1 измененных файлов с 7 добавлено и 4 удалено
  1. 7 4
      chatbot.py

+ 7 - 4
chatbot.py

@@ -11,6 +11,7 @@ import httpx
 import base64
 import re
 import signal
+import asyncio
 import sys
 
 from dotenv import load_dotenv
@@ -252,6 +253,8 @@ class MyDiscordClient(discord.Client):
     async def close(self):
         global openai_client
 
+        update_status.cancel()
+
         if openai_client is not None:
             await openai_client.close()
             openai_client = None
@@ -690,14 +693,14 @@ async def before_update_status():
 
 # Démarrer le bot Discord
 async def exit_app(signum=None):
-    globals.logger.debug("Received signal {}".format(signum))
-    globals.logger.info("Closing all tasks...")
+    logger.debug("Received signal {}".format(signum))
+    logger.info("Closing all tasks...")
 
     # On ferme la connexion à Discord
     if client_discord:
         await client_discord.close()
 	
-    globals.logger.critical("Script halted.")
+    logger.critical("Script halted.")
 
 def handle_signal(signum, frame):
     loop = asyncio.get_event_loop()
@@ -713,4 +716,4 @@ if __name__ == "__main__":
         # Démarrer le bot Discord
         client_discord.run(DISCORD_TOKEN)
     except Exception as e:
-        globals.logger.error("Encountered exception while running the bot: {}".format(e))
+        logger.error("Encountered exception while running the bot: {}".format(e))