From bf56a69aa40f175eb3fbd675a666a7603fa0a190 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 17 Apr 2020 12:44:17 -0400 Subject: [PATCH] fix multiple issues with users that have no roles in whois.ts --- src/commands/whois.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index dcd2d76..4f47c4d 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -61,14 +61,18 @@ export default class Whois extends Command { description += `\n<@${member.id}>`; embed.setDescription(description); - const roles = member.roles.map((r) => this.client.guilds.get(this.client.config.guildID).roles.get(r)).sort((a, b) => b.position - a.position); - - const { color } = roles.find((r) => r.color); - embed.setColor(color); + for (const role of member.roles.map((r) => this.client.guilds.get(this.client.config.guildID).roles.get(r)).sort((a, b) => b.position - a.position)) { + if (role?.color !== 0) { + embed.setColor(role.color); + break; + } + } embed.addField('Status', `${member.status[0].toUpperCase()}${member.status.slice(1)}`, true); embed.addField('Joined At', `${moment(new Date(message.member.joinedAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); embed.addField('Created At', `${moment(new Date(message.author.createdAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true); - embed.addField(`Roles [${roles.length}]`, roles.map((r) => `<@&${r.id}>`).join(', ')); + if (message.member.roles.length > 0) { + embed.addField(`Roles [${member.roles.length}]`, member.roles.map((r) => this.client.guilds.get(this.client.config.guildID).roles.get(r)).sort((a, b) => b.position - a.position).map((r) => `<@&${r.id}>`).join(', ')); + } const permissions: string[] = []; const serverAcknowledgements: string[] = []; const bit = member.permission.allow;