feat: only picking or captains allowed to /class

This commit is contained in:
ethanf 2023-11-30 18:10:22 -06:00
parent d266ac622c
commit 04fad613b6
2 changed files with 40 additions and 22 deletions

View File

@ -7,5 +7,6 @@
"PICKING_ID": "1175649967935856680", "PICKING_ID": "1175649967935856680",
"BLU_ID": "1175649793943552010", "BLU_ID": "1175649793943552010",
"RED_ID": "1175649777648680971", "RED_ID": "1175649777648680971",
"FK_ID": "1176396207183106078" "FK_ID": "1176396207183106078",
} "CAPTAIN_ID": "1178475124563919018"
}

View File

@ -7,13 +7,14 @@ const {
BLU_ID, BLU_ID,
RED_ID, RED_ID,
FK_ID, FK_ID,
CAPTAIN_ID,
} = require("./config.json"); } = require("./config.json");
const client = new Client({ const client = new Client({
intents: [ intents: [
GatewayIntentBits.Guilds, GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates GatewayIntentBits.GuildVoiceStates,
], ],
}); });
@ -38,33 +39,49 @@ client.on("interactionCreate", async (interaction) => {
command === "sniper" || command === "sniper" ||
command === "spy" command === "spy"
) { ) {
await interaction.deferReply(); // get voice channels
// get voice channel
const picking = interaction.guild.channels.cache.find( const picking = interaction.guild.channels.cache.find(
(channel) => channel.name === "picking" || channel.id === PICKING_ID (channel) => channel.name === "picking" || channel.id === PICKING_ID
); );
if (!picking) return console.error("Can't find channel 'picking'!"); if (!picking) return console.error("Can't find channel 'picking'!");
const captain = interaction.guild.channels.cache.find(
(channel) => channel.name === "captains" || channel.id === CAPTAIN_ID
);
if (!captain) return console.error("Can't find channel 'captains'!");
// set role name // make sure user is in picking or captain channel
let roleName = command; if (
if (command === "demoman") roleName = "demo"; !picking.members.has(interaction.user.id) &&
if (command === "engi") roleName = "engineer"; !captain.members.has(interaction.user.id)
) {
await interaction.reply({
content: "must be in picking or captains channel to use this command",
ephemeral: true,
});
return;
} else {
await interaction.deferReply();
// check each member in picking channel for role // set role name
let str = "In picking:"; let roleName = command;
for (const member of picking.members.values()) { if (command === "demoman") roleName = "demo";
if (member.roles.cache.find((role) => role.name === roleName)) { if (command === "engi") roleName = "engineer";
if (str !== "In picking:") str += ",";
str += " " + member.user.globalName; // 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 = "None found ¯\\_(ツ)_/¯";
if (str === "In picking:") str = "¯\\_(ツ)_/¯";
// respond // respond
return await interaction.editReply({ return await interaction.editReply({
content: str, content: str,
}); });
}
} }
if (interaction.channelId !== COMMAND_CHANNEL_ID) { if (interaction.channelId !== COMMAND_CHANNEL_ID) {