I am dealing with an array of objects, each containing an identifiers
array that includes strings. Among these strings is a Discord ID, but its position keeps changing unpredictably. This makes it impossible for me to reference the 4th identifier consistently.
All I require is the discord property.
https://i.sstatic.net/dQYFw.png
I have attempted various approaches, but I believe what I need is just the "discord" property. However, I am unsure how to tackle this and implement it in my code. Click on the image to learn more. You will find a json file there related to ${players[i].identifiers[4]
const updateMessage = function() {
getVars().then((vars) => {
getPlayers().then((players) => {
if (players.length !== LAST_COUNT) log(LOG_LEVELS.INFO,`${players.length} players`);
let queue = vars['Queue'];
let embed = UpdateEmbed()
.addField('Server Status','<:yes:847199217063297056> Online',true)
.addField('In Queue',queue === 'Enabled' || queue === undefined ? '0' : queue.split(':')[1].trim(),true)
.addField('Players Online',`${players.length}/${MAX_PLAYERS}\n\u200b\n`,true);
// .addField('\u200b','\u200b\n\u200b\n',true);
if (players.length > 0) {
// method D
const fieldCount = 3;
const fields = new Array(fieldCount);
fields.fill('');
// for (var i=0;i<players.length;i++) {
// fields[i%4 >= 2 ? 1 : 0] += `${players[i].name}${i % 2 === 0 ? '\u200e' : '\n\u200f'}`;
// }
fields[0] = `**Island Residents:**\n`;
for (var i=0;i<players.length;i++) {
fields[(i+1)%fieldCount] += `${players[i].name} [${players[i].id}], ${players[i].identifiers[4]}`;
}
for (var i=0;i<fields.length;i++) {
let field = fields[i];
if (field.length > 0) embed.addField('\u200b',`\n${fields[i]}`, true);
}
}
sendOrUpdate(embed);
LAST_COUNT = players.length;
}).catch(offline);
}).catch(offline);
TICK_N++;
if (TICK_N >= TICK_MAX) {
TICK_N = 0;
}
for (var i=0;i<loop_callbacks.length;i++) {
let callback = loop_callbacks.pop(0);
callback();
}
};