From 480e66abdff5aeb480b399df53d6d06c10227ade Mon Sep 17 00:00:00 2001 From: CBenni Date: Sun, 7 Jan 2018 15:51:19 +0100 Subject: [PATCH] Fixed offline people --- index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 7c08e58..e9dabed 100644 --- a/index.js +++ b/index.js @@ -174,21 +174,20 @@ client.login(config.discord.token).catch(error => { const discordAvatarRegex = /(https:\/\/cdn.discordapp.com\/avatars\/\w+\/\w+\.(\w+)\?size=)(\w+)/; -function findEmoji(message) { - console.log('Mentions:', message.mentions); +async function findEmoji(message) { // find a user mention - if (message.mentions.members.size > 0) { - const mentionedMember = message.mentions.members.first(); - const mentionedUser = mentionedMember.user; + if (message.mentions.users.size > 0) { + const mentionedUser = message.mentions.users.first(); + const mentionedMember = message.guild.members[mentionedUser.id]; let avatarUrl = mentionedUser.displayAvatarURL; const avatarMatch = discordAvatarRegex.exec(avatarUrl); if (avatarMatch) { - const ext = avatarMatch[2]; + // const ext = avatarMatch[2]; avatarUrl = `${avatarMatch[1]}128`; } return { - name: mentionedMember.displayName, - id: mentionedMember.id, + name: mentionedMember ? mentionedMember.displayName : mentionedUser.username, + id: mentionedUser.id, url: avatarUrl, ext: avatarUrl.indexOf('.gif') >= 0 ? 'gif' : 'png' }; @@ -251,7 +250,7 @@ client.on('message', async message => { if (message.cleanContent[0] === '/' || message.cleanContent[0] === '\\') { const messageSplit = message.cleanContent.split(' '); - const emoji = findEmoji(message); + const emoji = await findEmoji(message); let result = null; let count = 0; try {