penguin-band/commands/fklist.js
2024-03-26 23:56:43 -05:00

67 lines
1.7 KiB
JavaScript

import { SlashCommandBuilder } from "discord.js";
import { findChannelfromCache, findPlayer, getApplicableName } from "../utils";
import { ROLE_ID_RUNNER, VOICE_ID_PICKING, VOICE_ID_FK } from "../config.json";
// not really used since fks are now determined randomly
const data = new SlashCommandBuilder()
.setName("fklist")
.setDescription("Pulls addup channel members into fk channel and lists them");
const permissions = [ROLE_ID_RUNNER];
const synonyms = ["listfk"];
const execute = async (interaction) => {
await interaction.reply("Moving fatkids...");
// get voice channels
const picking = findChannelfromCache(
interaction.guild.channels.cache,
"picking",
VOICE_ID_PICKING
);
const fk = findChannelfromCache(
interaction.guild.channels.cache,
"fatkid",
VOICE_ID_FK
);
if (!picking || !fk) {
return console.error("Could not find all channels for /fklist");
}
// get members in voice channel
const members = picking.members;
if (members.size === 0) {
return await interaction.followUp("Found no members in picking");
}
let names = [],
eCount = 0;
const logFk = async (member) => {
try {
await member.voice.setChannel(fk);
names.push(getApplicableName(member));
} catch (error) {
console.error(error);
eCount++;
}
};
const logAllFks = async () => {
return Promise.all(
Array.from(members, async ([memberId, member]) => {
await logFk(member);
})
);
};
logAllFks().then(() =>
interaction.followUp(
`Fatkids: ${names.join(', ')}${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
)
);
};
export { data, permissions, execute, synonyms };