bug fix
This commit is contained in:
parent
c7a3316d45
commit
73636804a5
15
llamabot.js
15
llamabot.js
@ -145,6 +145,7 @@ client.on('messageCreate', async (message) => {
|
|||||||
|
|
||||||
const response = await generateResponse(conversation, message);
|
const response = await generateResponse(conversation, message);
|
||||||
|
|
||||||
|
|
||||||
// Append bot message to conversation history
|
// Append bot message to conversation history
|
||||||
conversation.messages.push({
|
conversation.messages.push({
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
@ -340,13 +341,13 @@ async function generateResponse(conversation, message) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// if the message object doesn't exist, create it
|
// if the message object doesn't exist, create it
|
||||||
if (!botMessage) {
|
if (botMessage == null) {
|
||||||
(async () => {
|
(async () => {
|
||||||
botMessage = await message.channel.send({ embeds: [embedData] });
|
botMessage = await message.channel.send({ embeds: [embedData] });
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
message.channel.messages.fetch(message.id)
|
message.channel.messages.fetch(botMessage.id)
|
||||||
.then(message => console.log(message.content)) //it fetched the message - good
|
.then(message => console.log(message.content)) //it fetched the message - good
|
||||||
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -362,13 +363,13 @@ async function generateResponse(conversation, message) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// if the message object doesn't exist, create it
|
// if the message object doesn't exist, create it
|
||||||
if (!botMessage) {
|
if (botMessage == null) {
|
||||||
(async () => {
|
(async () => {
|
||||||
botMessage = await message.channel.send({ embeds: [embedData] });
|
botMessage = await message.channel.send({ embeds: [embedData] });
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
message.channel.messages.fetch(message.id)
|
message.channel.messages.fetch(botMessage.id)
|
||||||
.then(message => console.log(message.content)) //it fetched the message - good
|
.then(message => console.log(message.content)) //it fetched the message - good
|
||||||
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -408,16 +409,18 @@ async function generateResponse(conversation, message) {
|
|||||||
|
|
||||||
const responseText = choice.message.content;
|
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
|
// clear the interval, replace the "please wait" message with the response, and update the message
|
||||||
clearInterval(refreshInterval);
|
await clearInterval(refreshInterval);
|
||||||
console.log(responseText);
|
console.log(responseText);
|
||||||
await botMessage.delete()
|
|
||||||
botMessage = null;
|
botMessage = null;
|
||||||
return responseText;
|
return responseText;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
|
botMessage = null;
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
time = 0
|
time = 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user