有没有一种方法可以将嵌入内容作为链接或指向图像的链接

时间:2020-07-31 12:27:37

标签: node.js discord.js

我将discord bot检测到的所有消息发送到我的控制台。我也做到了,因此它将所有链接发送到附件。这样一来,我可以看到Visual Studio中的所有消息。一切都很好。我有一个问题。我不知道如何从控制台看到嵌入内容。我希望能够从控制台中单击链接并查看嵌入内容。有什么办法吗?

如果您想知道这里是发送消息和附件的代码。

if(bot.user.id !== msg.author.id) console.log(`\n${msg.guild.name} || ${msg.channel.name} || ${msg.author.tag}: ${msg.content}`)
    let attam = 0
    msg.attachments.forEach(attachment=> {
        attam += 1
        console.log(`Attachment ${attam}: ${attachment.url}`)
    })

我想出了一种解决遮篷的方法。可能不是很好,但这是我做的。

console.log(msg.embeds.map(x => {
        attam ++
        let hmm = `embed ${attam}:`
        if(x.color){
            hmm = `${hmm}\nColor: ${x.hexColor}`
        }
        if(x.author){
            hmm = `${hmm}${x.author.iconURL? `\nAuthorImage: ${x.author.iconURL}`: ''}${x.author.name? `\nAuthor: ${x.author.name}`: ''}${x.author.url? `\nAuthorURL: ${x.author.url}`: ''}`
        }
        if(x.url){
            hmm = `${hmm}\nURL: ${x.hexColor}`
        }
        if(x.title){
            hmm = `${hmm}\nTitle: ${x.title}`
        }
        if(x.thumbnail){
            hmm = `${hmm}\nThumbnail: ${x.thumbnail.url}`
        }
        if(x.description){
            hmm = `${hmm}\nDescription: ${x.description}`
        }
        if(x.fields){
            let plus = 0
            x.fields.forEach(field => {
                plus++
                hmm = `${hmm}\nField ${plus}:\n   FieldTitle: ${field.name}\n   FieldValue: ${field.value}\n   Inline?: ${field.inline}`
            })
        }
        if(x.image) {
            hmm = `${hmm}\nImage: ${x.image.url}` 
        }
        if(x.footer){
            hmm = `${hmm}${x.footer.iconURL ? `\nFooterIcon: ${x.footer.iconURL}`: ''}${x.footer.text ? `\nFooterText: ${x.footer.text}`: ''}`
        }
        if(x.timestamp){
            hmm = `${hmm}\nTimestamp: ${x.timestamp}`
        }
        return hmm
        
    }).join("\n"))

我刚刚发现有一种称为toJSON()的嵌入方法。它实际上不会将其转换为实际的json字符串。它基本上将嵌入转换为具有属性的简单对象。我一直都可以做到。

msg.embeds.forEach(embed => {
    console.log(embed.toJSON())  
})

2 个答案:

答案 0 :(得分:1)

您可以使用message.embeds;这是Collection中的MessageEmbed

console.log(message.embeds.map(x => x.toString()).join("\n"))

答案 1 :(得分:1)

您可以这样做

client.on('message', (message) => {
    let images = message.embeds.map(embed => {
        if (embed.image) return embed.image
    })
});