From 5ffe1ab8d75bbcdae4dad5a2a0ae2d0cac4f5a85 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 28 Jun 2024 18:33:59 -0600 Subject: [PATCH] Add dispersal commands :trol: --- index.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/index.js b/index.js index 3824e47..01681d7 100644 --- a/index.js +++ b/index.js @@ -68,6 +68,24 @@ client.on('ready', () => { required: true } ] + }, + { + name: "disperse", + description: "Move people from one channel to random channels", + default_member_permissions: 16777216, + options: [ + { + name: "from", + description: "Channel to move people from (Voice Channel)", + type: 7, + required: true + } + ] + }, + { + name: "disperseall", + description: "Move people from all channels to random channels", + default_member_permissions: 16777216 } ] @@ -80,6 +98,11 @@ client.on('ready', () => { }); }); +const checkType = (channel) => { + // If its guild voice or stage return true + return channel.type == Discord.ChannelType.GuildVoice || channel.type == Discord.ChannelType.GuildStageVoice; +} + client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; switch (interaction.commandName) { @@ -92,6 +115,10 @@ client.on('interactionCreate', async interaction => { ephemeral: true }); } + if (!checkType(toChannel.type)) return interaction.reply({ + content: "You must specify a voice channel", + ephemeral: true + }); interaction.guild.channels.cache.forEach(channel => { if (channel?.type == Discord.ChannelType.GuildVoice) { channel.members.forEach(member => { @@ -115,6 +142,10 @@ client.on('interactionCreate', async interaction => { ephemeral: true }); } + if (!checkType(toChannel.type) || !checkType(fromChannel.type)) return interaction.reply({ + content: "You must specify a voice channel", + ephemeral: true + }); fromChannel?.members?.forEach(member => { member.voice?.setChannel(toChannel).catch(err => { // Do nothing, 99% missing permissions @@ -146,6 +177,10 @@ client.on('interactionCreate', async interaction => { ephemeral: true }); } + if (!checkType(channel.type)) return interaction.reply({ + content: "You must specify a voice channel", + ephemeral: true + }); channel?.members?.forEach(member => { member.voice?.setChannel(null).catch(err => { // Do nothing, 99% missing permissions @@ -156,6 +191,59 @@ client.on('interactionCreate', async interaction => { ephemeral: true }); break; + case "disperse": // Move people from one channel to random channels + // Get the channel to move people from + fromChannel = interaction.options.getChannel("from"); + // Check that fromChannel is in same guild as interaction + if (fromChannel?.guild != interaction.guild) { + return interaction.reply({ + content: "You must specify a voice channel in this server", + ephemeral: true + }); + } + if (!checkType(fromChannel.type)) return interaction.reply({ + content: "You must specify a voice channel", + ephemeral: true + }); + // Get all voice and stage channels in the guild + const voiceChannels = interaction.guild.channels.cache.filter(channel => checkType(channel.type)); + // Get all members in the fromChannel + const members = fromChannel.members; + // Loop through all members in the fromChannel + members.forEach(member => { + // Get a random channel from the voiceChannels + const randomChannel = voiceChannels.random(); + // Move the member to the random channel + member.voice.setChannel(randomChannel).catch(err => { + // Do nothing, 99% missing permissions + }); + }); + // Reply to the interaction + interaction.reply({ + content: "Moved all users from " + fromChannel.name + " to random channels", + ephemeral: true + }); + break; + case "disperseall": // Move people from all channels to random channels + // Get all voice and stage channels in the guild + const voiceChannelsAll = interaction.guild.channels.cache.filter(channel => checkType(channel.type)); + // Get all members in the fromChannel + const membersAll = interaction.guild.members.cache; + // Loop through all members in the fromChannel + membersAll.forEach(member => { + // Get a random channel from the voiceChannels + const randomChannel = voiceChannelsAll.random(); + // Move the member to the random channel + member.voice.setChannel(randomChannel).catch(err => { + // Do nothing, 99% missing permissions + }); + }); + // Reply to the interaction + interaction.reply({ + content: "Moved all users from all channels to random channels", + ephemeral: true + }); + break; } });