Ad

How To Find A Number In A Message On Discord?

I'm making a bot on discord and I want the bot to detect how much the person says in his message and who he mentioned, ex. >command @user 7853. I know that

message.mentions.users.first().id

finds the first-mentioned user but I don't know how to find the number that they said. Can someone tell me the correct script for that?

Ad

Answer

message.content is the content of the message so you only need to parse that like:

const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift();

This will convert the message into an array like ['@user', '7853']. Now you can just do args[1] and you will get the number.

If you are interested and want to learn more you can do here: https://discordjs.guide/, this is the guide made by the community of discord.js and includes a section about setting up commands you need.

Ad
source: stackoverflow.com
Ad