From 5c7758fa99dbe9b02e4979ba2a7a3000136c61a9 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Mon, 26 Apr 2021 14:32:55 -0500 Subject: [PATCH] Update usersWith command to select closest named role --- bot.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bot.js b/bot.js index 2a5560d..5d048bb 100644 --- a/bot.js +++ b/bot.js @@ -634,9 +634,16 @@ async function usersWith(message) { message.reply("query must contain at least 3 characters!") return; } - const roles = message.guild.roles.cache.filter(role => role.name.toLowerCase().includes(message.content.split(" ")[1].toLowerCase())); - const role = roles.array()[0]; - const membersList = roles.array()[0].members.array() + const queriedRole = message.content.split(" "); + queriedRole.shift(); + const roles = message.guild.roles.cache.filter(role => role.name.toLowerCase().includes(queriedRole.join(" ").toLowerCase())); + if (!roles.array().length) { + message.reply("no roles found with that name!"); + return; + } + const sortedRoles = roles.array().sort((a, b) => a.name.length - b.name.length); + const role = sortedRoles[0]; + const membersList = sortedRoles[0].members.array() if (membersList.length > threshold) { let embedContentArray = []; while(membersList.length) {