简体   繁体   中英

Discord.js: Pushing to array is combining strings

I am editing an embed message to update users that have "signed up" to a list by reacting. However, after my array length gets to 2, it begins combining the strings of the entire array before adding the new entry. Here is my code:

let newParticipant = getNickname(guildMembers) || user.tag;

//this line exists because "value" cannot be empty in an embed field
//so this removes the placeholder on the first entry

if (newEmbed.fields[2].value[0] === "0") {
    newEmbed.fields[2].value = [
        `${newEmbed.fields[2].value.length}. ${newParticipant}`,
    ];
} else {
    let participants = [newEmbed.fields[2].value];

    let newEntry = participants.length + 1 + ". " + newParticipant;
    participants.push(newEntry);

    newEmbed.fields[2] = { name: "Participants", value: participants };
    console.log(newEmbed.fields[2].value);
}

However this is the output I'm getting after 3 reactions:

[ '1. Cardinal' ]
[ '1. Cardinal', '2. Cardinal' ]
[ '1. Cardinal\n2. Cardinal', '2. Cardinal' ]

Is this something native to discord? Is my logic bad? I've tried using a spread operator when bringing in the array and several other things...

this worked. thank you Worthy Alpaca. I still wish I knew what exactly was happening lol.

let participants = newEmbed.fields[2].value;
        let num = participants.split("\n").length;
        let newEntry = `\n${num + 1}. ${newParticipant}`;
        participants += newEntry;

        newEmbed.fields[2] = { name: "Participants", value: participants };
        console.log(newEmbed.fields[2].value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM