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
} from 'discord.js';
let botMessage; // define a variable to hold the message object
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
@ -258,7 +260,6 @@ async function generateResponse(conversation, message) {
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
let botMessage; // define a variable to hold the message object
let time = 0
// define a function that shows the system load percentage and updates the message
const showSystemLoad = async () => {
@ -344,23 +345,35 @@ async function generateResponse(conversation, message) {
botMessage = await message.channel.send({ embeds: [embedData] });
})();
} 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 {
const embedData = {
color: 0x0099ff,
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 (!botMessage) {
(async () => {
(async () => {
botMessage = await message.channel.send({ embeds: [embedData] });
})();
} 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
clearInterval(refreshInterval);
console.log(responseText);
botMessage.delete()
await botMessage.delete()
botMessage = null;
return responseText;
} catch (err) {
@ -410,4 +423,4 @@ async function generateResponse(conversation, message) {
}
}
client.login(process.env.THE_TOKEN); // Replace with your bot token
client.login(process.env.THE_TOKEN); // Replace with your bot token