Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User ID #1

Closed
scratchyone opened this issue Mar 18, 2016 · 13 comments
Closed

User ID #1

scratchyone opened this issue Mar 18, 2016 · 13 comments

Comments

@scratchyone
Copy link
Contributor

How could I get a user name from a user ID, and a user id from a username? The getUser function returns null. Thanks!

@philliphenslee
Copy link
Owner

If using a username it would look something like this....

client.users.getUser('phil', function (err, result) {
        console.log(result.id);
    });

@scratchyone
Copy link
Contributor Author

Thanks! How would I get a name from an id?

@philliphenslee
Copy link
Owner

The same way, like this...

client.users.getUser('U0BC6D9V1', function (err, result) {
console.log(result.name);
});

@philliphenslee
Copy link
Owner

If you will log the entire result variable you can see the data that is accessible using result.fieldname

Hope this helps...

@scratchyone
Copy link
Contributor Author

Thanks! Great job on this module. I will close this unless I have any issues

@philliphenslee
Copy link
Owner

Thanks for the feedback and glad I could help.

@scratchyone
Copy link
Contributor Author

Hmm.

client.users.getUser('U0BC6D9V1', function (err, result) {
console.log(result.name);
});

returns result as null
I am using an ID from my room

@scratchyone scratchyone reopened this Mar 18, 2016
@philliphenslee
Copy link
Owner

For your room?

Write client.users to the console and see if you see your userid in the output.

Example:

var client = new SmartSlack(options);

// Login to Slack
client.start();

client.on('connected', function () {
    client.users.getUser('U0BC6D9V1', function (err, result) {
        console.log(result);
        console.log(client.users);
    });

@scratchyone
Copy link
Contributor Author

That worked!

@scratchyone
Copy link
Contributor Author

Thanks!

@scratchyone
Copy link
Contributor Author

It seems like the user IDs I used were invalid.

@philliphenslee
Copy link
Owner

Are you may have been calling it before the data was available in the cache. Glad you got it working.

@scratchyone
Copy link
Contributor Author

It looks like I was looking for message.user, instead of message.bot_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants