Reputation: 51
I have all the messages that the discord bot detects sent to my console. I also made it so it sends all the links to the attachment. This is so I can see all the messages from visual studio. This is all fine. I have a problem though. I don't know how to be able to see embeds from the console. I want to be able to click a link from the console and see the embed. Is there any way of doing that.
If you are wondering here is the code for sending the message and attachment.
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}`)
})
I figured out one way of solving my awnser. It is probably not that good but here is what I made.
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"))
I just discovered that there is a method for embeds called toJSON(). It does not actually convert it to an actual json string. It basically converts an embed to a simple object with properties. I all along could of just done.
msg.embeds.forEach(embed => {
console.log(embed.toJSON())
})
Upvotes: 0
Views: 232
Reputation: 2722
You can do it like this
client.on('message', (message) => {
let images = message.embeds.map(embed => {
if (embed.image) return embed.image
})
});
Upvotes: 1
Reputation: 786
You can use message.embeds
; this is a Collection
of MessageEmbed
s.
console.log(message.embeds.map(x => x.toString()).join("\n"))
Upvotes: 1