discord.io icon indicating copy to clipboard operation
discord.io copied to clipboard

getUser() returns undefined

Open HeartHeroDE opened this issue 6 years ago • 1 comments

I am trying to receive a User object with IDs from the member list of my server because I need the additional information from the User object. However, methods including the User object are very poorly documented and the getUser() function from the client always returns undefined.

This is a little help function that I am using. I changed the memberID part with a valid userID to make sure that it's not a problem about getting the right ID. bot is a Discord.Client object.

function get_user(memberID) { var user = bot.getUser({userID: "170974398587731968"}); return user; }

The problem is that I always get undefined and there is no error message or warning about permissions. The documentation also doesn't say if the getUser function is a callback function.

I am pretty sure that it's probably just a small problem. But I can't find the answer and would appreciate some help. Thanks in advance.

HeartHeroDE avatar Jun 30 '18 20:06 HeartHeroDE

I had the same problem. The simple workaround is using users property of the client, which is an Object of user Objects:

function get_user(memberID) { var user = bot.users[memberID]; return user; }

Still, I can't grasp why getUser don't work, but with a simple workaround, why use it?

JGPenaB avatar Sep 13 '18 18:09 JGPenaB