Okay, so I have a reaction mand that so far shows one image when the mand is used like it is supposed to. However, I have multiple images that I want it to choose from and show one randomly. Like how a math.random will choose a random sentence from a list. Except I want images instead of sentences. However, I would like it to say ${message.author} gave ${user} a hug! and then show the image, as how this code does:
if(mand === "hug") {
if(message.mentions.members.size == 1) {
let member = message.mentions.members.first()
message.channel.send(`${message.author} gave ${member} a hug!`, {
file: ".gif"
});
}
}
Again, I want it to take a random image from a list of images just like math.random does.
Okay, so I have a reaction mand that so far shows one image when the mand is used like it is supposed to. However, I have multiple images that I want it to choose from and show one randomly. Like how a math.random will choose a random sentence from a list. Except I want images instead of sentences. However, I would like it to say ${message.author} gave ${user} a hug! and then show the image, as how this code does:
if(mand === "hug") {
if(message.mentions.members.size == 1) {
let member = message.mentions.members.first()
message.channel.send(`${message.author} gave ${member} a hug!`, {
file: "https://media.giphy./media/CZpro4AZHs436/giphy.gif"
});
}
}
Again, I want it to take a random image from a list of images just like math.random does.
Share edited Apr 5, 2018 at 17:10 Sterling Archer 22.4k19 gold badges85 silver badges121 bronze badges asked Apr 5, 2018 at 17:08 Vampy MariaVampy Maria 251 gold badge1 silver badge8 bronze badges1 Answer
Reset to default 1Say you have an array:
const rando_imgs = [
'https://media.giphy./media/CZpro4AZHs436/giphy.gif',
'https://media.giphy./media/CZpro4AZHs436/giphy2.gif',
'https://media.giphy./media/CZpro4AZHs436/giphy3.gif',
]
You might pick from this array via:
message.channel.send(`${message.author} gave ${member} a hug!`, {
file: rando_imgs[Math.floor(Math.random() * rando_imgs.length)]
});