From ff5ac25392df2a46cc5e95b1d22a9eb64be9e49f Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:43:58 -0800 Subject: [PATCH] check that directory exists --- cogs/message_xp.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 34dbbf5..7291fb8 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -52,9 +52,13 @@ class MessageXP(BotBaseCog): self.logger.error(f"Error adding XP: {e}") def create_xp_file(self): - with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: - xp_data = {} - json.dump(xp_data, xp_file) + os.makedirs(self.data_dir, exist_ok=True) # Ensure the directory exists + xp_data = {} # Populate this with the required data + try: + with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: + json.dump(xp_data, xp_file) + except: + self.logger.error(f"Error creating XP file: {e}") async def setup(bot):