How to attach an image to an embed

自作多情 提交于 2021-02-11 15:08:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!