fix: async-friendly collection iteration
This commit is contained in:
parent
b1b71ebb18
commit
713f44835e
37
index.js
37
index.js
@ -163,24 +163,31 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
// move members to addup
|
// move members to addup
|
||||||
let idx = 0,
|
let idx = 0,
|
||||||
eCount = 0;
|
eCount = 0;
|
||||||
members.forEach(async (member) => {
|
|
||||||
idx++;
|
const moveToAddup = async (member) => {
|
||||||
console.log(idx, members.size);
|
|
||||||
try {
|
try {
|
||||||
await member.voice.setChannel(picking);
|
await member.voice.setChannel(picking);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
eCount++;
|
eCount++;
|
||||||
}
|
}
|
||||||
// respond when done
|
};
|
||||||
if (idx === members.size) {
|
|
||||||
return await interaction.followUp(
|
const moveAllToAddup = async () => {
|
||||||
`moved members in ${
|
return Promise.all(
|
||||||
command === "resetteams" ? "blu" : "addup, blu,"
|
Array.from(members, async ([memberId, member]) => {
|
||||||
} and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
|
await moveToAddup(member);
|
||||||
);
|
})
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
moveAllToAddup().then(() =>
|
||||||
|
interaction.followUp(
|
||||||
|
`moved members in ${
|
||||||
|
command === "resetteams" ? "blu" : "addup, blu,"
|
||||||
|
} and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command === "fk" || command === "fatkid") {
|
if (command === "fk" || command === "fatkid") {
|
||||||
@ -196,12 +203,12 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
);
|
);
|
||||||
if (!fk) return console.error("Can't find channel 'fatkid'!");
|
if (!fk) return console.error("Can't find channel 'fatkid'!");
|
||||||
|
|
||||||
|
// get members in voice channel
|
||||||
const members = picking.members;
|
const members = picking.members;
|
||||||
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
|
|
||||||
let str = "",
|
let str = "",
|
||||||
eCount = 0;
|
eCount = 0;
|
||||||
|
|
||||||
@ -216,7 +223,7 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const processAllEntries = async () => {
|
const logAllFks = async () => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
Array.from(members, async ([memberId, member]) => {
|
Array.from(members, async ([memberId, member]) => {
|
||||||
await logFk(member);
|
await logFk(member);
|
||||||
@ -224,7 +231,7 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
processAllEntries().then(() =>
|
logAllFks().then(() =>
|
||||||
interaction.followUp(
|
interaction.followUp(
|
||||||
`fatkids: ${str}${
|
`fatkids: ${str}${
|
||||||
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
eCount > 0 ? ` (error moving ${eCount} members)` : ""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user