From 005cd1c46d909dbd45dd13b91fbb5b290d352bf7 Mon Sep 17 00:00:00 2001 From: Loic Bersier Date: Sat, 8 Dec 2018 04:58:14 +0100 Subject: [PATCH] handle error --- commands/utility/taglist.js | 45 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/commands/utility/taglist.js b/commands/utility/taglist.js index 534cd60..87e68a0 100644 --- a/commands/utility/taglist.js +++ b/commands/utility/taglist.js @@ -17,23 +17,32 @@ module.exports = class taglistCommand extends Command { if(blacklist[message.author.id]) return message.channel.send("You are blacklisted") - let customresponse = new SelfReloadJSON(`./tag/${message.guild.id}.json`); - let count = Object.keys(customresponse).length - - fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ - if (err) - console.log(err); - let json = JSON.stringify(data) - json = json.replace(/[{}"\\]+/g, '') - json = json.replace(/,+/g, '\n') - const tagEmbed = new Discord.RichEmbed() - .setColor("#ff9900") - .setTitle('Tags list') - .setDescription(`Trigger:Response\n\n${json}`) - .setFooter(`You have ${count} tags on this server`) - - message.say(tagEmbed); - - }); + try { + let customresponse = new SelfReloadJSON(`./tag/${message.guild.id}.json`); + let count = Object.keys(customresponse).length + + + fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ + if (err) { + console.log(err); + } + let json = JSON.stringify(data) + json = json.replace(/[{}"\\]+/g, '') + json = json.replace(/,+/g, '\n') + const tagEmbed = new Discord.RichEmbed() + .setColor("#ff9900") + .setTitle('Tags list') + .setDescription(`Trigger:Response\n\n${json}`) + .setFooter(`You have ${count} tags on this server`) + + message.say(tagEmbed); + }); + } catch { + message.say('An error has occured, do you have any tags on the server?') } + + + + } + }; \ No newline at end of file