Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

How to get userid from username #317

Open
Unity123 opened this issue Jun 29, 2019 · 3 comments
Open

How to get userid from username #317

Unity123 opened this issue Jun 29, 2019 · 3 comments

Comments

@Unity123
Copy link

Unity123 commented Jun 29, 2019

I need to get the userid from the username so that my bot can mention a person given by the user.

@ClearlyElevated
Copy link

you can use any other bot or put a code block around the username to cause it not to work and give the user ID

@ClearlyElevated
Copy link

this isnt a lib issue

@soryy708
Copy link

soryy708 commented Dec 28, 2019

    function getUserId(bot, serverId, username) {
        const server = bot.servers[serverId];
        const userMatch = Object.values(bot.users).find(user => user.username.toLowerCase() === username.toLowerCase());
        if (userMatch) {
            return userMatch.id;
        }
        const nickMatch = Object.values(server.members).find(member => member.nick && member.nick.toLowerCase() === username.toLowerCase());
        if (nickMatch) {
            return nickMatch.id;
        }
        return null;
    }

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

No branches or pull requests

3 participants