Skip to content
Advertisement

Discord.js check if a user nickname contains Numbers and Letter, if yes add calculation to the number

I’m looking for a way to check if a discord users name contains numbers and certain letter, and if it does then apply a calculation to it.

For example I have a command that right now checks if the user has anything in the nickname, this adds the additional number next to the previous one (if there is one), if he doesn’t have anything as a nickname it makes the nickname UserName - {number} PRs. I’m looking for a way a to check if the user has {number} PRs in their name and if so, add the multiplyNum calculation to the existing number and preserve the rest of the name.

JavaScript

Advertisement

Answer

This should do I think. What you do is that you make nickname into array that splited by spaces and if last key is PRs and last key -1 is !NaN you run the calculation otherwise nothing is done.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement