最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord.js random image - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 1

Say 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)]
});
发布评论

评论列表(0)

  1. 暂无评论