如何在discord.js富嵌入上使用本地图像?
我有以下代码:如何在discord.js富嵌入上使用本地图像?,discord.js,Discord.js,我有以下代码: var datos = ["dato1","dato2","dato3"] console.log ("》" + message.author.username + " introdujo el comando: " + message.content + " en " + message.guild.name); let embed = new discord.RichEmbed() .setTitle("Datos sobre gatos Hello! U
var datos = ["dato1","dato2","dato3"]
console.log ("》" + message.author.username + " introdujo el comando: " + message.content + " en " + message.guild.name);
let embed = new discord.RichEmbed()
.setTitle("Datos sobre gatos Hello! Unfortunately, Discord's API only accepts URLs and not local paths.
You can only upload your images to a server/image hosting website and get the URL.This works for me.
const attachment = new Discord.Attachment('./card_images/sample.png', 'sample.png');
const embed = new RichEmbed()
.setTitle('Wicked Sweet Title')
.attachFile(attachment)
.setImage('attachment://sample.png');
message.channel.send({embed}).catch(console.error)
var datos=[“dato1”、“dato2”、“dato3”]
console.log(“>”+message.author.username+”introductionjo el-comando:“+message.content+”en“+message.guild.name”);
let embed=new discord.RichEmbed()
.setTitle(“Datos sobre gatos您好!不幸的是,Discord的API只接受URL而不接受本地路径。
您只能将图像上传到服务器/图像托管网站并获取URL。这对我很有用
const attachment = new Discord
.MessageAttachment('./card_images/sample.png', 'sample.png');
const embed = new Discord.MessageEmbed()
.setTitle('Wicked Sweet Title')
.attachFiles(attachment)
.setImage('attachment://sample.png');
message.channel.send({embed});
2020年,卢克将代码更新为Discord.js v12,供其他有同样问题的人使用
const attachment = new Discord.MessageAttachment('./help.png', 'help.png');
message.channel.send({
embed: {
files: [
attachment
],
image: {
url: 'attachment://help.png'
}
}
});
另一种方法是:
但在这种情况下,您没有使用丰富的嵌入。Rich Embeddes现在是v12中的MessageEmbeddes,此方法也是MessageEmbed,只是执行相同操作的另一种方法。您可以在文档中添加此格式的字段和其他所有内容