显示带有嵌入内容的 url (djs v12)
Displaying urls with embedded content (djs v12)
我希望在嵌入中显示图像/gif url,如果它有嵌入的内容,它将与 url 一起显示。目前,我只知道如果消息作为附件上传到discord时如何显示。
Example,头像显示在嵌入中。这与我想要的带有嵌入内容的图像的概念相同。
const embed = new MessageEmbed()
.setDescription(message.content)
.setColor("#E74C3C")
.setTimestamp()
.setImage(message.attachments.array().length == 0 ? null:message.attachments.first().url)
.setAuthor(
message.author.tag,
message.author.displayAvatarURL({ dynamic: true })
);
也许你可以试试 .setURL() ?
if(message.attachments.size > 0) {
embed.setURL(message.attachments.first().url)
}
据我了解,您正在尝试将图像设置到您嵌入的现有图像中,以便在我们放置 URL.
时显示的嵌入
您可以简单地使用 MessageEmbed
constructor's MessageEmbed#setImage()
方法以及从 link 中提取图像作为 URL 参数到方法,就像这样(为此您需要将它发送到先不和谐):
const { MessageEmbed } = require("discord.js")
message.channel.send("https://discord.com/").then( (embeddedmessage) => {
let image = embeddedmessage.embeds[0].thumbnail.url
const x = new MessageEmbed()
x.setTitle("Discord URL's Image")
x.setImage(image);
embeddedmessage.edit(x);
});
带有 URL 的消息(如果有嵌入)将有一个丰富的嵌入对象,这将证明其中存在的图像是合理的(这里是来自 URL 我们接受的示例对象我们的代码:
{
"title": "Discord | Your Place to Talk and Hang Out",
"type": "rich",
"description": "Discord is the easiest way to talk over voice, video, and text. Talk, chat, hang out, and stay close with your friends and communities.",
"url": "https://discord.com/",
"timestamp": null,
"color": null,
"fields": [],
"thumbnail": {
"url": "https://discord.com/assets/652f40427e1f5186ad54836074898279.png",
"proxyURL": "https://images-ext-2.discordapp.net/external/pL0w57uLXr8vYKityoLlH1CVuGCs0fB5xnrWKO8Fqoo/https/discord.com/assets/652f40427e1f5186ad54836074898279.png",
"height": 630,
"width": 1200
},
"image": null,
"author": null,
"footer": null
}
我希望在嵌入中显示图像/gif url,如果它有嵌入的内容,它将与 url 一起显示。目前,我只知道如果消息作为附件上传到discord时如何显示。
Example,头像显示在嵌入中。这与我想要的带有嵌入内容的图像的概念相同。
const embed = new MessageEmbed()
.setDescription(message.content)
.setColor("#E74C3C")
.setTimestamp()
.setImage(message.attachments.array().length == 0 ? null:message.attachments.first().url)
.setAuthor(
message.author.tag,
message.author.displayAvatarURL({ dynamic: true })
);
也许你可以试试 .setURL() ?
if(message.attachments.size > 0) {
embed.setURL(message.attachments.first().url)
}
据我了解,您正在尝试将图像设置到您嵌入的现有图像中,以便在我们放置 URL.
时显示的嵌入您可以简单地使用 MessageEmbed
constructor's MessageEmbed#setImage()
方法以及从 link 中提取图像作为 URL 参数到方法,就像这样(为此您需要将它发送到先不和谐):
const { MessageEmbed } = require("discord.js")
message.channel.send("https://discord.com/").then( (embeddedmessage) => {
let image = embeddedmessage.embeds[0].thumbnail.url
const x = new MessageEmbed()
x.setTitle("Discord URL's Image")
x.setImage(image);
embeddedmessage.edit(x);
});
带有 URL 的消息(如果有嵌入)将有一个丰富的嵌入对象,这将证明其中存在的图像是合理的(这里是来自 URL 我们接受的示例对象我们的代码:
{
"title": "Discord | Your Place to Talk and Hang Out",
"type": "rich",
"description": "Discord is the easiest way to talk over voice, video, and text. Talk, chat, hang out, and stay close with your friends and communities.",
"url": "https://discord.com/",
"timestamp": null,
"color": null,
"fields": [],
"thumbnail": {
"url": "https://discord.com/assets/652f40427e1f5186ad54836074898279.png",
"proxyURL": "https://images-ext-2.discordapp.net/external/pL0w57uLXr8vYKityoLlH1CVuGCs0fB5xnrWKO8Fqoo/https/discord.com/assets/652f40427e1f5186ad54836074898279.png",
"height": 630,
"width": 1200
},
"image": null,
"author": null,
"footer": null
}