From 73636804a5a00e7b6d39c3c8391037e095c7cac1 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sat, 20 May 2023 02:49:17 +0200 Subject: [PATCH] bug fix --- llamabot.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/llamabot.js b/llamabot.js index 10554ed..a994690 100644 --- a/llamabot.js +++ b/llamabot.js @@ -145,6 +145,7 @@ client.on('messageCreate', async (message) => { const response = await generateResponse(conversation, message); + // Append bot message to conversation history conversation.messages.push({ role: 'assistant', @@ -340,13 +341,13 @@ async function generateResponse(conversation, message) { }; // if the message object doesn't exist, create it - if (!botMessage) { + if (botMessage == null) { (async () => { botMessage = await message.channel.send({ embeds: [embedData] }); })(); } else { try { - message.channel.messages.fetch(message.id) + message.channel.messages.fetch(botMessage.id) .then(message => console.log(message.content)) //it fetched the message - good botMessage.edit({ embeds: [embedData] }); // otherwise, update the message } catch (error) { @@ -362,13 +363,13 @@ async function generateResponse(conversation, message) { }; // if the message object doesn't exist, create it - if (!botMessage) { + if (botMessage == null) { (async () => { botMessage = await message.channel.send({ embeds: [embedData] }); })(); } else { try { - message.channel.messages.fetch(message.id) + message.channel.messages.fetch(botMessage.id) .then(message => console.log(message.content)) //it fetched the message - good botMessage.edit({ embeds: [embedData] }); // otherwise, update the message } catch (error) { @@ -408,16 +409,18 @@ async function generateResponse(conversation, message) { const responseText = choice.message.content; + message.channel.messages.fetch(botMessage.id).then(message => message.delete()) + // clear the interval, replace the "please wait" message with the response, and update the message - clearInterval(refreshInterval); + await clearInterval(refreshInterval); console.log(responseText); - await botMessage.delete() botMessage = null; return responseText; } catch (err) { throw err; } finally { + botMessage = null; clearTimeout(timeout); time = 0 }