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) {
return await interaction.followUp("found no members in picking");
}
// get members in voice channel
let idx = 0,
eCount = 0,
str = "";
members.forEach(async (member) => {
idx++;
console.log(idx, members.size);
let str = "",
eCount = 0;
const logFk = async (key, member) => {
try {
await member.voice.setChannel(fk);
if (str.length > 0) str += ", ";
@ -215,15 +214,24 @@ client.on("interactionCreate", async (interaction) => {
console.error(error);
eCount++;
}
if (idx === members.size) {
// list members when done
return await interaction.followUp(
`fatkids: ${str}${
eCount > 0 ? ` (error moving ${eCount} members)` : ""
}`
);
}
});
};
const processAllEntries = async () => {
return Promise.all(
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)` : ""
}`
)
);
}
});