'Get user tag by user ID
how I can get user tag (example#0000 (No Mention)) by user ID?
const userid = message.channel.topic
bot.channels.get(`channelid`).send(`User ID: ${userid}\nUser Tag: ?????`)
Solution 1:[1]
let userid = "User ID";
let userTag = bot.users.cache.get(userid).username + "#" + bot.users.cache.get(userid).discriminator;
bot.channels.cache.get('Channel ID').send(`User ID: ${userid}\nUser Tag: ${userTag}`);
You simply have to store the users ID as a string in userid
. In userTag
you store the tag, you got from the users ID. Then you send the information to the channel.
userTag
returns Username#0000
.
Solution 2:[2]
Here's a bit of a simpler solution to your issue than the ones before, simply being that if you have the User ID of the user you're looking for, you can simply get the User object of the user you're looking for and get his tag using:
const user = client.users.cache.get(userid)
console.log(user.tag) // Simply returns the username and discriminator of the user. Ex. Bob#1234
Solution 3:[3]
how would you do something like
client.on("message", msg => {
if (msg.content === “test”) {
if (user.tag === “user tag here”)
“deletes message”
channel.send(auther, “Your not allowed to say that in this channel!”)
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Itamar S |
Solution 3 | DepressedChild |