Justice
Justice

Reputation: 3

How to attach an image to an embed

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;

Upvotes: 0

Views: 18082

Answers (2)

Xzandro
Xzandro

Reputation: 977

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.

Upvotes: 1

Matthew Baker
Matthew Baker

Reputation: 15

This has been depreciated with v14 In discord.js v14, we have a new way of sending attachments. We now have AttachmentBuilder but the code change should be pretty easy. Just import AttachmentBuilder from discord.js

Upvotes: 0

Related Questions