135 lines
3.8 KiB
JavaScript
135 lines
3.8 KiB
JavaScript
import { Client, GatewayIntentBits } from "discord.js";
|
|
const { token } = require("./config.json");
|
|
const client = new Client({
|
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
|
|
});
|
|
|
|
client.on("ready", () => {
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
});
|
|
|
|
client.on("interactionCreate", async (interaction) => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
if (interaction.channelId !== "1177469184192565288") {
|
|
await interaction.reply({
|
|
content: "wrong channel, or you lack the required permissions",
|
|
ephemeral: true,
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (interaction.commandName === "hello") {
|
|
await interaction.reply("world");
|
|
}
|
|
|
|
if (
|
|
interaction.commandName === "pullTeams" ||
|
|
interaction.commandName === "end"
|
|
) {
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
// get voice channels
|
|
const blu = interaction.guild.channels.cache.find(
|
|
(channel) =>
|
|
channel.name === "blu" || channel.id === "1175649793943552010"
|
|
);
|
|
if (!blu) return console.error("Can't find channel 'blu'!");
|
|
const red = interaction.guild.channels.cache.find(
|
|
(channel) =>
|
|
channel.name === "red" || channel.id === "1175649777648680971"
|
|
);
|
|
if (!red) return console.error("Can't find channel 'red'!");
|
|
const addup = interaction.guild.channels.cache.find(
|
|
(channel) =>
|
|
channel.name === "add-up" || channel.id === "1175649994674544721"
|
|
);
|
|
if (!addup) return console.error("Can't find channel 'add-up'!");
|
|
|
|
// get members in voice channel
|
|
const members = blu.members.concat(red.members);
|
|
if (members.size === 0) {
|
|
return await interaction.editReply("found no members in teams");
|
|
}
|
|
|
|
// move members to addup
|
|
let idx = 0,
|
|
eCount = 0;
|
|
members.forEach(async (member) => {
|
|
idx++;
|
|
try {
|
|
await member.voice.setChannel(addup);
|
|
} catch (error) {
|
|
console.error(error);
|
|
eCount++;
|
|
} finally {
|
|
// respond when done
|
|
if (idx === members.size) {
|
|
if (eCount > 0) {
|
|
return await interaction.editReply({
|
|
content: `moved teams, error moving ${eCount} members`,
|
|
});
|
|
}
|
|
return await interaction.editReply({
|
|
content: `moved teams`,
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
if (
|
|
interaction.commandName === "fk" ||
|
|
interaction.commandName === "fatkid"
|
|
) {
|
|
await interaction.deferReply();
|
|
|
|
// get voice channels
|
|
const addup = interaction.guild.channels.cache.find(
|
|
(channel) =>
|
|
channel.name === "add-up" || channel.id === "1175649994674544721"
|
|
);
|
|
if (!addup) return console.error("Can't find channel 'add-up'!");
|
|
const fk = interaction.guild.channels.cache.find(
|
|
(channel) =>
|
|
channel.name === "fatkid" || channel.id === "1176396207183106078"
|
|
);
|
|
if (!fk) return console.error("Can't find channel 'fatkid'!");
|
|
|
|
const members = addup.members;
|
|
if (members.size === 0) {
|
|
return await interaction.editReply("found no members in addup");
|
|
}
|
|
|
|
// get members in voice channel
|
|
let idx = 0,
|
|
eCount = 0,
|
|
str = "";
|
|
members.forEach(async (member) => {
|
|
idx++;
|
|
try {
|
|
await member.voice.setChannel(fk);
|
|
if (str.length > 0) str += ", ";
|
|
str += member.user.globalName;
|
|
} catch (error) {
|
|
console.error(error);
|
|
eCount++;
|
|
} finally {
|
|
// list members when done
|
|
if (idx === members.size) {
|
|
if (eCount > 0) {
|
|
return await interaction.editReply({
|
|
content: `fatkids: ${str}, error moving ${eCount} members`,
|
|
});
|
|
}
|
|
return await interaction.editReply({
|
|
content: `fatkids: ${str}`,
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
client.login(token);
|