【问题标题】:Is there a way of getting an embed as a link or a link to an image有没有办法将嵌入作为链接或图像链接
【发布时间】:2020-08-09 02:31:20
【问题描述】:

我已将 discord 机器人检测到的所有消息发送到我的控制台。我也做了它,所以它将所有链接发送到附件。这样我就可以看到来自 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())  
})

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

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

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

    【讨论】:

    • 这将返回 [object Object]。无论如何,这不会发生。抱歉回复晚了
    • 尝试:console.log(require('util').inspect(message.embeds.map(x => x.toString()).join("\n"), { depth: 0 }));
    • 遗憾的是,我自己已经创建了一些替代方案,但无论如何感谢。
    • 好的,请务必发布您的替代方案,以便我们对此提供反馈并供将来参考。
    • 这可能不是最好的选择,但我基本上对每个嵌入属性都做了这样的一行。嵌入属性:值 --- 这包括图像链接。如果你想看代码告诉我。抱歉回复晚了
    【解决方案2】:

    你可以这样做

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

    【讨论】:

    • 这个方法只会返回嵌入的图片;不是 tnrei 嵌入自身。
    • or a link to an image
    猜你喜欢
    • 2019-07-12
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    • 2019-06-17
    • 2016-09-19
    • 2017-02-14
    相关资源
    最近更新 更多