From 640823b95e6bea80e35df666d7d60ea2af83c478 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 28 Apr 2021 10:59:35 -0500 Subject: [PATCH] Fix role array sorting --- bot.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot.js b/bot.js index 6552927..479cb92 100644 --- a/bot.js +++ b/bot.js @@ -269,7 +269,8 @@ async function reactionRole(message) { return; } - const role = roles.array()[0]; + const sortedRoles = roles.array().sort((a, b) => a.name.length - b.name.length); + const role = sortedRoles[0]; const verificationEmbed = new Discord.MessageEmbed() .setTitle(`Are you sure you would like ${reaction.emoji.name} to correspond to the **${role.name}** role?`) @@ -590,7 +591,8 @@ async function roleInfo(message) { return; } - const role = roles.array()[0]; + const sortedRoles = roles.array().sort((a, b) => a.name.length - b.name.length); + const role = sortedRoles[0]; const roleInfoEmbed = new Discord.MessageEmbed() .setTitle(`Role \`${role.name}\` Info`) @@ -639,7 +641,8 @@ async function addRole(message) { return; } - const role = roles.array()[0]; + const sortedRoles = roles.array().sort((a, b) => a.name.length - b.name.length); + const role = sortedRoles[0]; const members = message.guild.members.cache.filter(member => { if (member.nickname) { @@ -970,7 +973,8 @@ async function roleRequest(message) { return; } - const role = roles.array()[0]; + const sortedRoles = roles.array().sort((a, b) => a.name.length - b.name.length); + const role = sortedRoles[0]; if (message.member.roles.cache.has(role.id)) { message.reply("you already have that role!");