如何将图像附加到嵌入
How to attach an image to an embed
我想弄清楚这个问题已经有一段时间了。
我不知道如何让机器人将图像附加到嵌入。
我正在尝试从我的 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;
由于您希望从本地磁盘上传图片,因此您需要准确地告诉 Discord 嵌入。
每个嵌入都有一个 .attachFile() 方法,您可以在其中从本地磁盘上传文件并直接在您的嵌入中使用它,语法如下:attachment://fileName.extension
因此,作为一个名为 avatar.png 的文件的示例,您需要
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);
如果您需要一次上传多个文件,请使用.attachFiles()方法。
我想弄清楚这个问题已经有一段时间了。 我不知道如何让机器人将图像附加到嵌入。 我正在尝试从我的 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;
由于您希望从本地磁盘上传图片,因此您需要准确地告诉 Discord 嵌入。
每个嵌入都有一个 .attachFile() 方法,您可以在其中从本地磁盘上传文件并直接在您的嵌入中使用它,语法如下:attachment://fileName.extension
因此,作为一个名为 avatar.png 的文件的示例,您需要
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);
如果您需要一次上传多个文件,请使用.attachFiles()方法。