Fixed offline people
This commit is contained in:
parent
c3ee2fbc43
commit
480e66abdf
1 changed files with 8 additions and 9 deletions
17
index.js
17
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+)/;
|
const discordAvatarRegex = /(https:\/\/cdn.discordapp.com\/avatars\/\w+\/\w+\.(\w+)\?size=)(\w+)/;
|
||||||
|
|
||||||
function findEmoji(message) {
|
async function findEmoji(message) {
|
||||||
console.log('Mentions:', message.mentions);
|
|
||||||
// find a user mention
|
// find a user mention
|
||||||
if (message.mentions.members.size > 0) {
|
if (message.mentions.users.size > 0) {
|
||||||
const mentionedMember = message.mentions.members.first();
|
const mentionedUser = message.mentions.users.first();
|
||||||
const mentionedUser = mentionedMember.user;
|
const mentionedMember = message.guild.members[mentionedUser.id];
|
||||||
let avatarUrl = mentionedUser.displayAvatarURL;
|
let avatarUrl = mentionedUser.displayAvatarURL;
|
||||||
const avatarMatch = discordAvatarRegex.exec(avatarUrl);
|
const avatarMatch = discordAvatarRegex.exec(avatarUrl);
|
||||||
if (avatarMatch) {
|
if (avatarMatch) {
|
||||||
const ext = avatarMatch[2];
|
// const ext = avatarMatch[2];
|
||||||
avatarUrl = `${avatarMatch[1]}128`;
|
avatarUrl = `${avatarMatch[1]}128`;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name: mentionedMember.displayName,
|
name: mentionedMember ? mentionedMember.displayName : mentionedUser.username,
|
||||||
id: mentionedMember.id,
|
id: mentionedUser.id,
|
||||||
url: avatarUrl,
|
url: avatarUrl,
|
||||||
ext: avatarUrl.indexOf('.gif') >= 0 ? 'gif' : 'png'
|
ext: avatarUrl.indexOf('.gif') >= 0 ? 'gif' : 'png'
|
||||||
};
|
};
|
||||||
|
@ -251,7 +250,7 @@ client.on('message', async message => {
|
||||||
|
|
||||||
if (message.cleanContent[0] === '/' || message.cleanContent[0] === '\\') {
|
if (message.cleanContent[0] === '/' || message.cleanContent[0] === '\\') {
|
||||||
const messageSplit = message.cleanContent.split(' ');
|
const messageSplit = message.cleanContent.split(' ');
|
||||||
const emoji = findEmoji(message);
|
const emoji = await findEmoji(message);
|
||||||
let result = null;
|
let result = null;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
try {
|
try {
|
||||||
|
|
Reference in a new issue