collegeDropOut330
collegeDropOut330

Reputation: 23

Discord bot image does not show up

I am trying to send an image using discord.js, but the image shows up as a downloadable file instead of the actual image

I have tried using the same method but with a url that ends in .jpg or .png and it works. This link is a png image but it doesn't have the extension

client.on('message', (msg) => {
  if (msg.content === 'ping') {
    msg.channel.send("new message ", {file: 
          "https://www.tradingview.com/x/uNzxW3Is"});
   }
});

Upvotes: 0

Views: 2245

Answers (1)

Robert Dyjas
Robert Dyjas

Reputation: 5227

If you specify file name, it works correctly:

msg.channel.send({
  files: [{
    attachment: 'https://www.tradingview.com/x/uNzxW3Is',
    name: 'file.jpg'
  }]});

Apparently the library is not smart enough to convert the file to desired extension automatically (or perhaps not supposed to do so), so you have to specify that it's an image.

Also, it's worth mentioning, that file property of MessageOptions is deprecated, so you should use files instead.

Upvotes: 3

Related Questions