Reputation: 1
iam trying to make my bot read the complete data in a embed and i do want my bot to send the data in the exact format as the original and inside a embed can anyone help me please
bot.on("message", msg => {
if(msg.embed){
msg.channel.send(msg.embed.content)
}
});
When i try the above code it says can not read content of undefined
I am a beginner so if i made any mistakes please help me
Upvotes: 0
Views: 2812
Reputation: 1056
There is no embed
property on the Message object. But there is an embeds
property instead, which is an array of MessageEmbeds.
You can iterate through all embeds in the message using:
bot.on("message", (msg) => {
msg.embeds.forEach((embed) => {
console.log(embed.title);
console.log(embed.description);
});
});
However, description
might not be available if the embed just contains fields or a picture etc. You can see the full list of properties that an embed can contain here.
If the embed does contain fields, you can use the fields
property in the MessageEmbed class, which is an array of EmbedFields.
You can look through all fields in all embeds using this:
bot.on("message", (msg) => {
msg.embeds.forEach((embed) => {
let fields = embed.fields;
fields.forEach((field) => {
console.log(field.name);
console.log(field.value);
});
});
});
Upvotes: 1