wip: replacing foreach with smth async friendly

This commit is contained in:
ethanf 2024-01-16 15:49:30 -06:00
parent 1c4aff27de
commit 0381ee9fde

View File

@ -200,13 +200,12 @@ client.on("interactionCreate", async (interaction) => {
if (members.size === 0) { if (members.size === 0) {
return await interaction.followUp("found no members in picking"); return await interaction.followUp("found no members in picking");
} }
// get members in voice channel // get members in voice channel
let idx = 0, let str = "",
eCount = 0, eCount = 0;
str = "";
members.forEach(async (member) => { const logFk = async (key, member) => {
idx++;
console.log(idx, members.size);
try { try {
await member.voice.setChannel(fk); await member.voice.setChannel(fk);
if (str.length > 0) str += ", "; if (str.length > 0) str += ", ";
@ -215,15 +214,24 @@ client.on("interactionCreate", async (interaction) => {
console.error(error); console.error(error);
eCount++; eCount++;
} }
if (idx === members.size) { };
// list members when done
return await interaction.followUp( const processAllEntries = async () => {
`fatkids: ${str}${ return Promise.all(
eCount > 0 ? ` (error moving ${eCount} members)` : "" Array.from(members, async ([key, value]) => {
}` console.log(key, value); // what are these?
); await logFk(key, value);
} })
}); );
};
processAllEntries().then(() =>
interaction.followUp(
`fatkids: ${str}${
eCount > 0 ? ` (error moving ${eCount} members)` : ""
}`
)
);
} }
}); });