N
N
Nikita NeVajno2019-11-20 20:32:21
JavaScript
Nikita NeVajno, 2019-11-20 20:32:21

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

spoiler
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}`)
    }
}

Most likely I didn't write message.mentions.users.displayAvatarURL correctly, probably it needs to be written somehow differently.
In the console it only shows this
spoiler
Collection [Map] {
  '645703812501209101' => ClientUser {
    id: '645703812501209101',
    bot: true,
    username: 'Niro',
    discriminator: '0124',
    avatar: 'aa63416d9e5114775ce94d462a317737',
    lastMessageID: null,
    lastMessageChannelID: null,
    verified: undefined,
    mfaEnabled: null,
    _typing: Map {}
  }
}

Where is the avatar I have no idea and have no idea what it is. I don't think this is the intended link

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fgvnovoross, 2019-11-24
@Pangsit

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, верно?...

That's all, everything else seems to be correct! ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question