From e02eace3eac560ca34ad10ffa91f75c0f15817f8 Mon Sep 17 00:00:00 2001 From: Loic Bersier Date: Thu, 6 Dec 2018 19:05:40 +0100 Subject: [PATCH] did i fix --- commands/utility/tag.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/commands/utility/tag.js b/commands/utility/tag.js index a001ead9..f7fb3642 100644 --- a/commands/utility/tag.js +++ b/commands/utility/tag.js @@ -38,17 +38,20 @@ module.exports = class CustomResponseCommand extends Command { let json = JSON.stringify(customresponse) - fs.writeFile(`DiscordBot/tag/${message.guild.id}.json`, '{}', function (err) { - if (err){ - console.log(err); - } - }) + fs.readFile(`DiscordBot/tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ if (err){ console.log(err); } else { customresponse = JSON.parse(data); //now it an object + if (customresponse == '{}') { + fs.writeFile(`DiscordBot/tag/${message.guild.id}.json`, '{}', function (err) { + if (err){ + console.log(err); + } + }) + } customresponse [trigger] = response json = JSON.stringify(customresponse); //convert it back to json fs.writeFile(`DiscordBot/tag/${message.guild.id}.json`, json, 'utf8', function(err) {