discord.io
discord.io copied to clipboard
How to get userid from username
I need to get the userid from the username so that my bot can mention a person given by the user.
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
this isnt a lib issue
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;
}