【发布时间】: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