問題描述
我試圖讓我的消息看起來像 this,但由于 interaction.reply
我得到的是 this.
I'm trying to make my message look like this, but as a result of interaction.reply
I get this instead.
這是我的代碼:
fs.readdir("./pics", (error, files) => {
if (error) return console.log(error)
const num = (Math.floor(Math.random() * files.length)+1).toString();
const imagembed = new Discord.MessageEmbed()
.setTitle("Some cute pic for you!")
.setColor("#980002")
.setFooter("Requested by " + interaction.member.user.tag);
interaction.reply({ embeds: [imagembed], files: [`./pics/${num}.jpg`]})
})
有什么解決辦法嗎?
推薦答案
將圖像附加到嵌入中
在嵌入中附加圖像可以使用 <代碼>MessageEmbed.setImage().這需要一個有效的圖片鏈接.
Attaching images to embeds
Attaching images in embeds can be achieved using MessageEmbed.setImage()
. This requires a valid link to picture.
自從 MessageEmbed.setImage()
是唯一的方法,要將圖像附加到嵌入中,您必須使用一些技巧.您必須將圖像作為文件發送到 MessagePayload代碼> 并將其添加到嵌入中.
Since MessageEmbed.setImage()
is the only way, to attach an image to an embed, you have to use some trickery. You have to send the image as file in your MessagePayload
and add it to the embed.
const embed = new discord.MessageEmbed().setImage("attachment://image.png");
interaction.reply({ embeds: [embed ], files: [`./path/to/image.png`] });
解決您的問題
對你來說,這將導致以下代碼:
Solution to your problem
For you, this would result in the following code:
fs.readdir("./pics", (error, files) => {
if (error) return console.log(error)
const num = (Math.floor(Math.random() * files.length) + 1).toString();
const imagembed = new Discord.MessageEmbed()
.setTitle("Some cute pic for you!")
.setColor("#980002")
.setFooter("Requested by " + interaction.member.user.tag)
.setImage(`attachment://${num}.jpg`);
interaction.reply({ embeds: [imagembed], files: [`./pics/${num}.jpg`] })
})
這篇關于與嵌入分開發送附件的 Djs 交互的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!