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; - }); + } }, };