penny09
penny09

Reputation: 15

How to get picture sent in message? Discord.js

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].

Upvotes: 1

Views: 7263

Answers (1)

Cipher
Cipher

Reputation: 2722

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)

Upvotes: 4

Related Questions