feat: class role commands

This commit is contained in:
ethanf 2023-11-29 01:59:15 -06:00
parent 131478222f
commit d266ac622c
2 changed files with 93 additions and 3 deletions

View File

@ -10,7 +10,11 @@ const {
} = require("./config.json"); } = require("./config.json");
const client = new Client({ const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates], intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates
],
}); });
client.on("ready", () => { client.on("ready", () => {
@ -21,6 +25,48 @@ client.on("interactionCreate", async (interaction) => {
const command = interaction.commandName; const command = interaction.commandName;
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
if (
command === "scout" ||
command === "soldier" ||
command === "pyro" ||
command === "demoman" ||
command === "demo" ||
command === "heavy" ||
command === "engineer" ||
command === "engi" ||
command === "medic" ||
command === "sniper" ||
command === "spy"
) {
await interaction.deferReply();
// get voice channel
const picking = interaction.guild.channels.cache.find(
(channel) => channel.name === "picking" || channel.id === PICKING_ID
);
if (!picking) return console.error("Can't find channel 'picking'!");
// set role name
let roleName = command;
if (command === "demoman") roleName = "demo";
if (command === "engi") roleName = "engineer";
// check each member in picking channel for role
let str = "In picking:";
for (const member of picking.members.values()) {
if (member.roles.cache.find((role) => role.name === roleName)) {
if (str !== "In picking:") str += ",";
str += " " + member.user.globalName;
}
}
if (str === "In picking:") str = "¯\\_(ツ)_/¯";
// respond
return await interaction.editReply({
content: str,
});
}
if (interaction.channelId !== COMMAND_CHANNEL_ID) { if (interaction.channelId !== COMMAND_CHANNEL_ID) {
await interaction.reply({ await interaction.reply({
content: "wrong channel, or you lack the required permissions", content: "wrong channel, or you lack the required permissions",
@ -85,7 +131,7 @@ client.on("interactionCreate", async (interaction) => {
return await interaction.editReply({ return await interaction.editReply({
content: `moved members in ${ content: `moved members in ${
command === "resetteams" ? "blu" : "addup, blu," command === "resetteams" ? "blu" : "addup, blu,"
} and red.${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`, } and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`,
}); });
} }
} }

View File

@ -25,7 +25,51 @@ const commands = [
{ {
name: "fk", name: "fk",
description: "Pulls addup channel members into fk channel and lists them", description: "Pulls addup channel members into fk channel and lists them",
} },
{
name: "scout",
description: "Lists picking channel members with scout role",
},
{
name: "soldier",
description: "Lists picking channel members with soldier role",
},
{
name: "pyro",
description: "Lists picking channel members with pyro role",
},
{
name: "demo",
description: "Lists picking channel members with demo role",
},
{
name: "demoman",
description: "Alias of /demo",
},
{
name: "heavy",
description: "Lists picking channel members with heavy role",
},
{
name: "engineer",
description: "Lists picking channel members with engineer role",
},
{
name: "engi",
description: "Alias of /engineer",
},
{
name: "medic",
description: "Lists picking channel members with medic role",
},
{
name: "sniper",
description: "Lists picking channel members with sniper role",
},
{
name: "spy",
description: "Lists picking channel members with spy role",
},
]; ];
const rest = new REST({ version: "10" }).setToken(TOKEN); const rest = new REST({ version: "10" }).setToken(TOKEN);