I'm wondering how I can get the 4 digit user ID of a discord user from a message. For example, PruinaTempestatis#8487. Can someone help me?
If the number always appears after a single hash #
then you can simply do a split on that string and get the second value of the array like this:
USING SPLIT
var str = 'PruinaTempestatis#8487'; var digits = str.split('#')[1]; console.log(digits);
USING REGEX
var str = 'PruinaTempestatis#8487'; var digits = str.replace( /^\D+/g, ''); console.log(digits);
USING SUBSTRING
var str = 'PruinaTempestatis#8487'; var digits = str.substr(str.indexOf('#')+1, str.length); console.log(digits);
Using user.tag
message.channel.send(message.user.tag)
Split their tag into an array and get the last element.
member.user.tag.split('#')[-1];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.