图片Discord.js

时间:2019-04-12 21:35:25

标签: node.js discord.js

我想为随机嵌入到图片中的消息添加名称  我想为图像指定自定义名称。 我用'let'代码尝试了一下。我刚启动Javascript。请帮助...:)

const Discord = require('discord.js');
module.exports.run = async (bot, message, args) => {
    const pic = [Jhin = 'https://cdn.discordapp.com/attachments/562384674505228303/562981534332878869/607280.png',
        Kalista = 'https://cdn.discordapp.com/attachments/562384674505228303/562981683268157455/654259.jpg'];
    const pics = Math.floor((Math.random() * pic.length));
    const test = new Discord.RichEmbed()


        .setTitle('<JHIN OR KALISTA>')
        .setColor('RANDOM')
        .setFooter('BKBOT')
        .setImage(pic[pics]);

    message.channel.send(test);
};
exports.conf = {
    enabled: true,
    guildOnly: false,
    aliases: [''],
    permLevel: 0,
};

exports.help = {
    name: 'test',
    description: 'Rastgele komik paylaşımlar atar.',
    usage: 'kp',
};

1 个答案:

答案 0 :(得分:0)

您可以通过首先设置一个对象数组来代表每个人的方法来进行操作。它们的名称将具有name属性,而您要显示的图片的URL具有image属性。然后,您可以生成一个随机数来表示数组中所选值的索引。您的代码将类似于...

let people = [
{name: 'Jhin', image: 'url'},
{name: 'Kalista', image: 'url'}
];

let person = people[Math.floor(Math.random()*people.length)];

let embed = new Discord.RichEmbed()
.setTitle(person.name)
.setColor('#ffffff')
.setFooter('BKBOT')
.setImage(person.image);
message.channel.send(embed);