This commit is contained in:
Raven Scott 2023-05-19 23:49:55 +02:00
parent 1fe0f20e6f
commit c7a3316d45

View File

@ -15,6 +15,8 @@ import {
Partials Partials
} from 'discord.js'; } from 'discord.js';
let botMessage; // define a variable to hold the message object
const client = new Client({ const client = new Client({
intents: [ intents: [
GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessages,
@ -258,7 +260,6 @@ async function generateResponse(conversation, message) {
const messagesCopy = [...conversation.messages]; // create a copy of the messages array const messagesCopy = [...conversation.messages]; // create a copy of the messages array
let botMessage; // define a variable to hold the message object
let time = 0 let time = 0
// define a function that shows the system load percentage and updates the message // define a function that shows the system load percentage and updates the message
const showSystemLoad = async () => { const showSystemLoad = async () => {
@ -344,23 +345,35 @@ async function generateResponse(conversation, message) {
botMessage = await message.channel.send({ embeds: [embedData] }); botMessage = await message.channel.send({ embeds: [embedData] });
})(); })();
} else { } else {
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message try {
message.channel.messages.fetch(message.id)
.then(message => console.log(message.content)) //it fetched the message - good
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
} catch (error) {
return; //the message no longer exists and will be ignored
}
} }
}); });
} else { } else {
const embedData = { const embedData = {
color: 0x0099ff, color: 0x0099ff,
title: 'Please wait.. I am thinking...', title: 'Please wait.. I am thinking...',
fields: filedsData, // It seems like a typo, it should be `filedsData` instead of `filedsData` fields: filedsData,
}; };
// if the message object doesn't exist, create it // if the message object doesn't exist, create it
if (!botMessage) { if (!botMessage) {
(async () => { (async () => {
botMessage = await message.channel.send({ embeds: [embedData] }); botMessage = await message.channel.send({ embeds: [embedData] });
})(); })();
} else { } else {
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message try {
message.channel.messages.fetch(message.id)
.then(message => console.log(message.content)) //it fetched the message - good
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
} catch (error) {
return; //the message no longer exists and will be ignored
}
} }
} }
@ -398,8 +411,8 @@ async function generateResponse(conversation, message) {
// 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); clearInterval(refreshInterval);
console.log(responseText); console.log(responseText);
botMessage.delete() await botMessage.delete()
botMessage = null;
return responseText; return responseText;
} catch (err) { } catch (err) {