Discord.js |随机图像嵌入

时间:2020-07-29 10:59:31

标签: javascript node.js discord discord.js

我想知道如何在嵌入图像中放置随机图像:

这是我的代码:

case 'aes':
  number = 100;
  imageNumber = Math.floor (Math.random() * (number - 1 + 1)) + 1;
  message.channel.send( {files: ["./images/" + imageNumber + ".jpg"] } )
  break;

我如何使图像以嵌入形式发布?

1 个答案:

答案 0 :(得分:1)

您可以这样做。

case 'aes':
let maxImageNumber = 100;
let imageNumber = Math.floor (Math.random() * (maxImageNumber - 1 + 1)) + 1;
let imageName = `${imageNumber}.jpg`
let imagePath = `./images/${imageName}`

let file = new Discord.MessageAttachment(imagePath);
let embed = new Discord.MessageEmbed();
    embed.setImage(`attachment://${imageName}`)
message.channel.send({ files: [file], embed: embed });
break;