From 2e35c2dc458cfdab792c1b76e8f70b64e7f28ef1 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Sun, 17 Aug 2025 23:20:12 +0200 Subject: [PATCH] modified: bot.py --- bot.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index ce39daf..117d518 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -__version__ = "dev-0.9.3" +__version__ = "dev-0.9.4" __all__ = ["Discordbot-chatai (Discord)"] __author__ = "SimolZimol" @@ -1326,6 +1326,16 @@ async def process_ai_queue(): try: user_history = user_data.get(user_history_field, []) + + # Ensure user_history is a list, not a string + if isinstance(user_history, str): + try: + user_history = json.loads(user_history) + except (json.JSONDecodeError, ValueError): + user_history = [] + elif not isinstance(user_history, list): + user_history = [] + user_history.append({"role": "user", "content": f"{user_name}: {prompt}"}) messages = [ @@ -1366,7 +1376,7 @@ async def process_ai_queue(): user_history.append({"role": "assistant", "content": assistant_message}) # Update the relevant user history field - update_user_data(user_data["user_id"], guild_id, user_history_field, json.dumps(user_history)) + update_user_data(user_data["user_id"], guild_id, user_history_field, user_history) except Exception as e: logger.error(f"Processing errors: {e}")