我有这个代码:
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 ")
.setColor(12118406)
.setDescription(datos[Math.floor(Math.random() * datos.length)])
.setFooter("© 2018 República Gamer LLC", bot.user.avatarURL)
.setImage("http://i.imgur.com/sYyH2IM.png")
message.channel.send({embed})
.catch ((err) => {
console.error(err);
let embed = new discord.RichEmbed()
.setColor(15806281)
.setTitle("? Ocurrió un error")
.setDescription("Ocurrió un error durante la ejecución del comando")
message.channel.send({embed})
})
Run Code Online (Sandbox Code Playgroud)
如何使用本地图像路径代替 URL(在 .setImage() 行上)
小智 13
将 Luke 的代码更新为 Discord.js v12,供 2020 年遇到同样问题的其他人使用
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});
Run Code Online (Sandbox Code Playgroud)
小智 13
在discord.js v13 及更高版本中,MessageEmbed#attachFiles已弃用。从现在开始,您应该直接将文件添加到响应中。
MessageEmbed#attachFiles 已被删除;文件现在应该直接附加到消息而不是嵌入。
// Before v13
const embed = new Discord.MessageEmbed().setTitle('Attachments').attachFiles(['./image1.png', './image2.jpg']);
channel.send(embed);
// v13
const embed = new Discord.MessageEmbed().setTitle('Attachment').setImage('attachment://image.png');
channel.send({ embeds: [embed], files: ['./image.png'] });
Run Code Online (Sandbox Code Playgroud)
小智 7
这对我有用。
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)
Run Code Online (Sandbox Code Playgroud)