diff --git a/.gitignore b/.gitignore index 7c732c3..1171896 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea venv __pycache__ -.env \ No newline at end of file +.env +error_* \ No newline at end of file diff --git a/bot.py b/bot.py index e78b9f6..fee8310 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,5 @@ import os +import traceback import discord from datetime import datetime from dotenv import load_dotenv @@ -8,7 +9,7 @@ import emotes import help from utils import debug -VERSION = "1.1" +VERSION = "1.2" t0 = datetime.now() # Loading token @@ -87,5 +88,22 @@ async def on_message(message): await COMMANDS[args[0]](message, args) -# Launch client -client.run(token) +print(f"Current PID: {os.getpid()}") + +# Launch client and rerun on errors +while True: + try: + client.run(token) + break # clean kill + except Exception as e: + t = datetime.now() + print(f"Exception raised at {t:%Y-%m-%d %H:%M} : {repr(e)}") + fileName = f"error_{t:%Y-%m-%d_%H-%M-%S}.txt" + if os.path.exists(fileName): + print("Two many errors, killing") + break + with open(fileName, 'w') as f: + f.write(f"Discord Analyst v{VERSION} started at {t0:%Y-%m-%d %H:%M}\r\n" + f"Exception raised at {t:%Y-%m-%d %H:%M}\r\n" + f"\r\n" + f"{traceback.format_exc()}")