我想知道如何在嵌入图像中放置随机图像:
这是我的代码:
case 'aes':
number = 100;
imageNumber = Math.floor (Math.random() * (number - 1 + 1)) + 1;
message.channel.send( {files: ["./images/" + imageNumber + ".jpg"] } )
break;
我如何使图像以嵌入形式发布?
答案 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;