So, I'm looking to create a password generator function in discord.js, and I'd like to include [a-z][A-Z][0-9], whilst all being optional (I'd like for the user to be able to determine what to include in the password, for example whether they want lower and uppercase or only one). I've been trying to figure this out for a bit now and can't quite get it right (I'm pretty new to all this).
This is what I have so far:
if (message.content === `${prefix}pwgen`) {
const random = (length = 8) => {
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let str = '';
for (let i = 0; i < length; i++) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
}
return str;
};
This is some code I got from https://attacomsian.com/blog/javascript-generate-random-string but obviously, here, he uses console.log to get results from the block of code, but here I'd like to be able to have the user send a number on Discord so the bot generates a random string of that length, and then have the bot return it in Discord. How can I do this? Thanks!