1

I have script in discord.js to send message.content and message.attachments eg. picture from user in bot message.

Script:

client.on("message", message => {
    message.channel.send({
         "embed": {
            "color": 14680086,
            "description": message.content + message.attachments,
            "author": {
                "icon_url": "url to some picture",
                "url": "url to some picture",
                "name": "some text"
            }
        }
    })
})

Bot sends message.content but when I add a picture I get [object Map].

MrMythical
  • 8,908
  • 2
  • 17
  • 45
penny09
  • 15
  • 1
  • 5

1 Answers1

4

message.attachments is a discord collection, so you can't add it to embed description. The one way to do it, it check if message has attachment, then add it into embed.image

client.on('message', async message => {
    let messageAttachment = message.attachments.size > 0 ? message.attachments.array()[0].url : null
    let embed = new Discord.MessageEmbed();
        embed.setAuthor(message.author.tag, message.author.avatarURL())
        if (messageAttachment) embed.setImage(messageAttachment)
        embed.setColor(14680086)
        await message.channel.send(embed)
        message.delete()
})
client.login(token)
MrMythical
  • 8,908
  • 2
  • 17
  • 45
Cipher
  • 2,702
  • 1
  • 6
  • 17
  • I have one more question. How in this case I can delete user message. Because when i add message.delete at the end bot send empty message. Something like this: 1. User send message 2. Bot send user message in embed 3. Bot delete user message – penny09 Jul 28 '20 at 09:33
  • If you delete user message with image, image will deleted too, so you need yo save image to local storage and then use it in embed. – Cipher Jul 28 '20 at 10:36
  • How can i save image in local storage in this case? – penny09 Jul 28 '20 at 10:43
  • You can use [download-file](https://www.npmjs.com/package/download-file) as varian. Or use http and pipe [example](https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries) – Cipher Jul 28 '20 at 13:47