This commit is contained in:
Raven Scott 2023-05-20 02:49:17 +02:00
parent c7a3316d45
commit 73636804a5
1 changed files with 9 additions and 6 deletions

View File

@ -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
}