Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a user ID from a mention

I want to get a Users ID from a mention. I am making a user info command so the author of the message will not always be them so I cannot do message.author.id. I have used substrings to split the command into the command itself and the mention but I cannot turn the mention into an ID.

I am aware that discords mentions are actually <@USERID>, which is another way I could get the ID. Please tell me if I am able to get rid of the <@> so I am left with the ID, or turn the mention itself into an one using another method. I have looked through the docs and I am not aware of anything that could help me.

like image 805
OffstageAlmond Avatar asked Dec 17 '22 21:12

OffstageAlmond


1 Answers

You can do that in two ways: if you want to use the mention as an argument, you can remove the mention characters with regex, like this: yourstring.replace(/[\\<>@#&!]/g, "");.
The other way to do that is to get the first mention in the message and then the user's id: message.mentions.users.first().id.

like image 54
Federico Grandi Avatar answered Dec 28 '22 09:12

Federico Grandi