infamous
infamous

Reputation: 3

Discord JS getting text and value of a field

I have been trying to make it so whenever an embed is sent, I gather it and then I try to send it in another channel.

I can't get the value and name which are inside the field.

My code:

client.on('message', message => {
    if (message.channel.id == channel1)
    {
        console.log(message.embeds);
        console.log("------------------------");
        console.log("------------------------");
        console.log("------------------------");
        console.log("------------------------");
        console.log(message.embeds[0].title);
        console.log(message.embeds[0].description);
        console.log(message.embeds[0].color);
        console.log(message.embeds[0].fields);
        console.log(message.embeds[0].image.url);
        console.log(message.embeds[0].footer.text);
    }
 });

How I tried to retrieve the name and value inside of the field:

 message.embeds[0].fields.name
 message.embeds[0].fields.value

But these return undefined, so I don't know how to retrieve the value.

Upvotes: 0

Views: 848

Answers (1)

MrMythical
MrMythical

Reputation: 9041

MessageEmbed.fields is an array. You need to get the first element from that to read the name and value

console.log(message.embeds[0].fields[0].name);
console.log(message.embeds[0].fields[0].value);

Keep in mind fields[0] may be undefined if there are no fields

Upvotes: 1

Related Questions