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}")