Attempt at fixing user sessions not closing which left the bot in a busy state

This commit is contained in:
Raven Scott 2023-03-26 01:44:43 +02:00
parent 91ad04aeb3
commit 5ea2e73942

View File

@ -1,6 +1,8 @@
const { MessageEmbed } = require('discord.js');
const axios = require('axios');
const jsonfile = require('jsonfile');
const util = require('util');
const readFile = util.promisify(jsonfile.readFile);
let session2;
let isProcessing = false; // Semaphore variable
@ -25,8 +27,8 @@ module.exports = {
// Set the semaphore to true
isProcessing = true;
await jsonfile.readFile(file, async function (err, session) {
if (err) return interaction.editReply('Please create a session using /create-session.');
try {
const session = await readFile(file);
session2 = session.id;
@ -49,9 +51,12 @@ module.exports = {
console.log(response.data.answer);
interaction.editReply(response.data.answer);
} catch (err) {
console.error(err);
interaction.editReply('Please create a session using /create-session.');
} finally {
// Set the semaphore to false
isProcessing = false;
});
}
},
};