I’m working on a Discord bot and I’m stuck. I want to make it generate several different random alphanumeric codes when a user types a command. Right now, it only makes one code twice. Here’s what I have so far:
const { MessageEmbed } = require('discord.js');
const settings = require('../settings.json');
module.exports = {
name: 'generate',
description: 'Create random alphanumeric codes',
run(msg) {
if (msg.channel.id !== settings.codeChannel) {
msg.channel.send(
new MessageEmbed()
.setColor(settings.colors.main)
.setTitle('Incorrect Channel')
.setDescription(`Please use <#${settings.codeChannel}> to generate codes`)
.setFooter(msg.author.tag, msg.author.displayAvatarURL({ dynamic: true, size: 64 }))
.setTimestamp()
);
return;
}
const code = Math.random().toString(36).substring(7);
msg.channel.send(
new MessageEmbed()
.setColor(settings.colors.main)
.setTitle('Codes Generated')
.setDescription(`${code}\n${code}`)
.setFooter(msg.author.tag, msg.author.displayAvatarURL({ dynamic: true, size: 64 }))
.setTimestamp()
);
}
};
How can I change this to create multiple unique codes instead of repeating the same one? Any help would be great!