wip: replacing foreach with smth async friendly
This commit is contained in:
parent
1c4aff27de
commit
0381ee9fde
30
index.js
30
index.js
@ -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,16 +214,25 @@ 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 () => {
|
||||||
|
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}${
|
`fatkids: ${str}${
|
||||||
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
||||||
}`
|
}`
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
client.login(TOKEN);
|
client.login(TOKEN);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user