#How to get avatarURL from user id?

26 messages · Page 1 of 1 (latest)

peak sphinx
#

I tried everything i can possibly do. Please help me.
Discord.js: v13.9.1
Node: v16 or smth like that idk

short scarab
#

fetch the user, then you can use the avatarURL method

peak sphinx
short scarab
#

fetch returns a promise and avatarURL is a method

peak sphinx
#

for context; i have 2 arguments. top ones are directly the user's id and bottom ones are converted ones

short scarab
#

you should use fetch instead of cache.get for users, it checks cache first by default

peak sphinx
short scarab
#

you didn't set the token yet (via client.login) when you tried to execute the above code

short scarab
#

your bot's token, that you pass to client.login

#

without it you can't make most api requests

peak sphinx
peak sphinx
#

Up

bright carbon
peak sphinx
#

this is a command file

#

how tf it got that error it wasn't getting it until i changed it to fetch

bright carbon
#

You can’t access the api until your bot is logged in

bright carbon
peak sphinx
#

the reason i'm mentioning about it because it was working perfectly fine until i changed cache.get to fetch

#

like how does that effect the token directly

bright carbon
#

Fetch tries to hit the API, where get looks in the cache and returns undefined (untested)

#

In order to fetch users your bot needs to have logged in and authenticated beforehand

#

If you have those fetch statements out side of where your command executes it’s likely that those lines are running when you try and define your command.

peak sphinx
#

end of index.js