So I'm new to Coding and I wanted to make a discord bot, I have an idea of how to do it, but I can't figure out how to do what I want. I was wondering if there is a way to add a bunch of photos a file and have the discord bot be able to pull a a random picture out of it to send it? As well as maybe on that pulls like 5 random ones and sends them?
I have no idea what to do, and I haven't found anything to help with it.
Currently I'm doing one where I have to add every image ID on its own and make really long lines of code for every command.
Any ideas???
Array.prototype.rand = function() {
return this[Math.floor((Math.random()*this.length))];
}
console.log(["a","b","c"].rand())
(new edit since my previous answer didn't seem to sit right with some people)
You can use Math.random() to pick a random image out of an array of images.
const imageArray = [...];
const randomImage = imageArray[Math.floor(Math.random()*imageArray.length)];