How to make random colors for embeds Discord.js
Solution 1:
If you want to pick a colour from an array of values, you can create a helper function and use that:
function random(colors) {
return colors[Math.floor(Math.random() * colors.length)];
};
random(['#008000', '#E50000']);
// => "#E50000" or "#008000"
In your example:
const embed = new Discord
.MessageEmbed()
.setColor(random(['#008000', '#E50000']));
If you want to pick a totally random colour value, the .setColor()
method accepts specific colour strings. One of them is 'RANDOM`, which sets the colour to a random value:
const embed = new Discord
.MessageEmbed()
.setColor('RANDOM');
Solution 2:
There is no need to write something complex all by yourself. Instead, you can use:
Embed.setColor('RANDOM')
This is an inbuilt feature of the discord.js
library.