From 0273e57e7f5dc1d5609c84571b10a06676420c7d Mon Sep 17 00:00:00 2001 From: chris062689 Date: Sun, 15 Jan 2017 12:38:31 -0500 Subject: [PATCH] Fixed count.forEach being undefined. Presented a message when the user had no warnings. --- commands/clearWarnings.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/commands/clearWarnings.js b/commands/clearWarnings.js index f81935b..f1a6fa6 100644 --- a/commands/clearWarnings.js +++ b/commands/clearWarnings.js @@ -5,12 +5,15 @@ var logger = require('../logging.js'); exports.roles = ['Admins', 'Moderators']; exports.command = function(message) { message.mentions.users.map((user) => { - var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length || 0; + var count = app.warnings.filter(x => x.id == user.id && !x.cleared).length; + if (count != null && count.length > 0) { + count.forEach(warning => warning.cleared = true); + data.flushWarnings(); + message.channel.sendMessage(`${user}, your warnings have been cleared.`); + } else { + message.channel.sendMessage(`${user}, you have no warnings to clear.`); + } - count.forEach(warning => warning.cleared = true); - data.flushWarnings(); - - message.channel.sendMessage(`${user}, your warnings have been cleared.`); logger.info(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); app.logChannel.sendMessage(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); });