Giter VIP home page Giter VIP logo

Comments (2)

jamboj avatar jamboj commented on June 16, 2024 9

Thank you @almostSouji
This works:

var img = await Jimp.read('https://i.imgur.com/wSTFkRM.png');
var imgBuf = await img.getBufferAsync(Jimp.AUTO);

const exampleEmbed = new Discord.RichEmbed()
.setTitle('important title')
.setDescription('meaningful description')
.attachFiles([{name: "image.png", attachment:imgBuf}])
.setImage('attachment://image.png');

discordChannel.send(exampleEmbed);

However this doesn't work if you don't use '.png' at the end of 'file' name and it also should not just give a crooked output if used incorrectly.

Re redundancy - I think you missed my point, my code snippet is just using a file but the point is to illustrate work with a local buffer. In real life application one might not have a file.

I did see the warnings and I googled far and deep and did try every possible combination I could think of before opening this issue, so I think you might need to update the code or at least add an example of working with buffer here: https://discordjs.guide/popular-topics/embeds.html#using-the-richembed-constructor

otherwise it seems like really hard to discover. Thanks again for your prompt reply and giving a hint that finally solved my issue

from guide.

almostSouji avatar almostSouji commented on June 16, 2024

As you can see here attachFiles takes an array of FileOptions which may include a name and the attachment itself.
Naming the file then allows you to properly reference it from the setImage method, which I hoped the yellow warnings all over the guide would suggest.

There's also quite some redundancy in your snippet as you can directly provide an URL as buffer to above mentioned attachment property.
If you have the image on imgur anyways reattaching it is however not even needed as you can simply set embed images to an URL directly.

Edit: If you require more information/help with the approach please visit the Discord server: https://discord.gg/bRCvFy9

from guide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.