问题
I've been trying to figure this out for a while. I can't figure out how to make a bot attach an image to an embed. I'm trying to upload a picture from my PC.
const commando = require('discord.js-commando');
const discord = require('discord.js')
class HoundCommand extends commando.Command {
constructor(client) {
super(client, {
name: 'hound',
group: 'simple',
memberName: 'hound',
description: 'Tells info about hound'
});
}
async run(message, args) {
var myInfo = new discord.RichEmbed()
.setTitle("Hound")
.addField("Name", "Hound")
.addField("Age", "12")
.addField("Description", "Im good at siege, I stream occasionally and ya")
.setColor("#020B0C")
message.channel.sendEmbed(myInfo);
}
}
module.exports = HoundCommand;
回答1:
Since you want your image uploaded from your local disk you need to tell the Discord embed exactly that.
Every embed has a .attachFile() method, where you can upload a file from local disk and directly use this in your embed with the following syntax: attachment://fileName.extension
So as an example with an file called avatar.png you would need
var myInfo = new discord.RichEmbed()
.setTitle("Hound")
.addField("Name", "Hound")
.addField("Age", "12")
.addField("Description", "Im good at siege, I stream occasionally and ya")
.setColor("#020B0C")
.attachFile('./avatar.png')
.setImage('attachment://avatar.png');
message.channel.sendEmbed(myInfo);
If you need to upload multiple files at once, use the .attachFiles() method.
来源:https://stackoverflow.com/questions/54067769/how-to-attach-an-image-to-an-embed