javascript - How to get picture sent in message? Discord.js - Stack Overflow

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

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

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

Share Improve this question edited Nov 15, 2021 at 14:21 MrMythical 9,0393 gold badges21 silver badges48 bronze badges asked Jul 27, 2020 at 22:05 penny09penny09 151 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745222326a4617305.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信