From 5ea2e7394212b93240a874c9bff7b2bf62aed99d Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 26 Mar 2023 01:44:43 +0200 Subject: [PATCH] Attempt at fixing user sessions not closing which left the bot in a busy state --- commands/Info/chat.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/commands/Info/chat.js b/commands/Info/chat.js index 989a2c2..e9573f0 100644 --- a/commands/Info/chat.js +++ b/commands/Info/chat.js @@ -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; - }); + } }, };