How do I make my discord bot send random images?

I was wondering how you can make your discord bot give images when someone gives a command. I’m also using an embed for it as well so for the .setImage I’m not sure what to do. Thank you!

Can’t really tell you on how to send Discord embeds, but I can tell you can get random images from an array.

Say you have an array of images:

var images = ["image1", "image2", "image3"];

And we want to get a random one. Well, there is no built-in function to do so, so we can make one by using a prototype (don’t need to know what it does, but if you want to learn, click here:

Array.prototype.random = function() {
  return this[Math.floor(Math.random() * this.length)]
};

Now on our images array, we can call that function:

images.random();

and it should return a image.

Thank you!

1 Like