From 7e6b71c802dadf2dcef41149d892e2382f3a3ef1 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sun, 29 Aug 2021 20:12:56 -0600 Subject: [PATCH] utility.avatar: fetch member if possible --- src/modules/utility.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/modules/utility.js b/src/modules/utility.js index e39e129..d5ffbd3 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -100,14 +100,25 @@ avatar.callback = async function (msg, line) { ) { return user; } else { - const avatar = user.avatar || user.user.avatar; - const url = `${AVATAR_BASE}${user.id}/${avatar}.${ + let member = user; + if (msg.channel.guild) { + if (msg.channel.guild.members.has(user.id)) { + member = msg.channel.guild.members.get(user.id); + } else { + const fetched = await msg.channel.guild.fetchMembers({ + userIDs: [user.id], + }); + member = fetched[0]; + } + } + const avatar = member.avatar || member.user.avatar; + const url = `${AVATAR_BASE}${member.id}/${avatar}.${ avatar.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024" }`; return { embeds: [ { - title: `Avatar for \`${user.username}#${user.discriminator}\``, + title: `Avatar for \`${member.username}#${member.discriminator}\``, url, image: { url,