#any way to get the user from userID?
44 messages · Page 1 of 1 (latest)
member: <Guild>.members.fetch("id")
user (if you don't need guild data or don't have a guild available in the context): <Client>.users.fetch("id")
either will reject the returned promise if not a part of a guild (only for member) or wrong id
that didnt seem to work
lemme do it and send u the logs
client.users.fetch(userid).then((user) => {
console.log(user);
}).catch(console.error);```
why are you fetching a user if you have one nayways?
oh, nvm, userid, i read user.id
mhm
and this worked
my god
every time i seek for help it starts working for no reason
lol
really
odd
i do know you need to fetch the user, because the user data we usually get doesn't include it but... that's quite literally what you are doing with that
ah, it is cached, so the fetch short-circuits
(fetch always tries to hit the cache before the api and resolves with the cached user data, if available)
force-fetch (so it actually hits the API)
.fetch(id, true)
that is turning into base js now
how can i bring the user value outside of the block
Resources to understand Promise:
• MDN: learn more
• Guide: learn more
• JavaScript info: learn more
the "user" variable is only valid within the then callback function
anything that needs to happen afterwards needs to be within that scope
yeah so how can i bring it outside of that
you don't
what?
the main point of getting the user info is using it elsewhere
i think you should read both what i just said as well as the resources in the tag above
without understanding promises this will be a bit of a pain. anything we do that hits the API will return a promise, familiarising yourself with them is def. recommended
okay alright
so apparently a promise is a value that a function returns ?
fetch returns one, yes