Answer the question
In order to leave comments, you need to log in
Can't find user's avatar. How to fix?
Hello.
I'm trying to make a command that will display a link to the avatar of the user who will be mentioned.
Example "It turned out something like this, but it does not work, it just gives out undefined I
am attaching the code
module.exports = {
name : "avatar",
description : "Эта функция позволит Вам-узнать ссылку на аватарку пользователя.",
async execute(message, args) {
if (args.length > 1) new Error('Только 1 или 0');
if (!args.length) {
return message.channel.send(`Ваша аватарка: ${message.author.displayAvatarURL}`)
}
if (!message.mentions.users.size) new Error('Упомините [email protected]~ пользователя');
console.log(message.mentions.users)
return message.channel.send(`А вот ссылка:${message.mentions.users.displayAvatarURL}`)
}
}
Collection [Map] {
'645703812501209101' => ClientUser {
id: '645703812501209101',
bot: true,
username: 'Niro',
discriminator: '0124',
avatar: 'aa63416d9e5114775ce94d462a317737',
lastMessageID: null,
lastMessageChannelID: null,
verified: undefined,
mfaEnabled: null,
_typing: Map {}
}
}
Answer the question
In order to leave comments, you need to log in
SilverStorm , I know what he's talking about. Users is Map.
Nikita NeVajno :
1. There was an error in the first code because the user does not have a displayAvatarURL variable. To get it, you need to contact member. To get an avatar from user, you need to remove the inscription display, because There simply - user.avatarURL
So you incorrectly indicated the error. It is necessary to show what is at the top, but what you have given does not say anything. You are correct in your comment.
2. The Discord is not defined error occurs because it is not the main working script in which you declared a Discord constant (or variable). It is not in this script and you did not import it. You write in the first line of this script
const Discord = require("discord.js"); //Вы же не пользуетесь command, верно?...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question