feat: only picking or captains allowed to /class
This commit is contained in:
parent
d266ac622c
commit
04fad613b6
@ -7,5 +7,6 @@
|
||||
"PICKING_ID": "1175649967935856680",
|
||||
"BLU_ID": "1175649793943552010",
|
||||
"RED_ID": "1175649777648680971",
|
||||
"FK_ID": "1176396207183106078"
|
||||
}
|
||||
"FK_ID": "1176396207183106078",
|
||||
"CAPTAIN_ID": "1178475124563919018"
|
||||
}
|
||||
|
||||
57
index.js
57
index.js
@ -7,13 +7,14 @@ const {
|
||||
BLU_ID,
|
||||
RED_ID,
|
||||
FK_ID,
|
||||
CAPTAIN_ID,
|
||||
} = require("./config.json");
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildVoiceStates
|
||||
GatewayIntentBits.GuildVoiceStates,
|
||||
],
|
||||
});
|
||||
|
||||
@ -38,33 +39,49 @@ client.on("interactionCreate", async (interaction) => {
|
||||
command === "sniper" ||
|
||||
command === "spy"
|
||||
) {
|
||||
await interaction.deferReply();
|
||||
|
||||
// get voice channel
|
||||
// get voice channels
|
||||
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'!");
|
||||
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
|
||||
let roleName = command;
|
||||
if (command === "demoman") roleName = "demo";
|
||||
if (command === "engi") roleName = "engineer";
|
||||
// make sure user is in picking or captain channel
|
||||
if (
|
||||
!picking.members.has(interaction.user.id) &&
|
||||
!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
|
||||
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;
|
||||
// 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 = "¯\\_(ツ)_/¯";
|
||||
if (str === "In picking:") str = "None found ¯\\_(ツ)_/¯";
|
||||
|
||||
// respond
|
||||
return await interaction.editReply({
|
||||
content: str,
|
||||
});
|
||||
// respond
|
||||
return await interaction.editReply({
|
||||
content: str,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (interaction.channelId !== COMMAND_CHANNEL_ID) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user