// Requires require('dotenv').config(); const Discord = require('discord.js'); const colors = require('colors'); const { REST, Routes } = require('discord.js'); const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN); // Setup Discord const client = new Discord.Client({ intents: ["Guilds", "GuildVoiceStates"] }); client.on('ready', () => { console.log(`${colors.cyan("[INFO]")} Logged in as ${colors.green(client.user.displayName)}`); const commands = [ { name: "moveall", description: "Move people from all channels to one channel", default_member_permissions: 16777216, options: [ { name: "to", description: "Channel to move people to (Voice Channel)", type: 7, required: true } ] }, { name: "move", description: "Move people from one channel to another", default_member_permissions: 16777216, options: [ { name: "from", description: "Channel to move people from (Voice Channel)", type: 7, required: true }, { name: "to", description: "Channel to move people to (Voice Channel)", type: 7, required: true } ] }, { name: "disconnectall", description: "Disconnect all users from voice channels", default_member_permissions: 16777216 }, { name: "disconnect", description: "Disconnect users from a voice channel", default_member_permissions: 16777216, options: [ { name: "channel", description: "Channel to disconnect users from (Voice Channel)", type: 7, required: true } ] } ] console.log(`${colors.cyan("[INFO]")} Started refreshing application (/) commands.`); rest.put( Routes.applicationCommands(client.user.id), { body: commands }).then(() => { console.log(`${colors.cyan("[INFO]")} Successfully reloaded application (/) commands.`); }); }); client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; switch (interaction.commandName) { case "moveall": toChannel = interaction.options.getChannel("to"); // Check that toChannel is in same guild as interaction if (toChannel?.guild != interaction.guild) { return interaction.reply({ content: "You must specify a voice channel in this server", ephemeral: true }); } interaction.guild.channels.cache.forEach(channel => { if (channel?.type == Discord.ChannelType.GuildVoice) { channel.members.forEach(member => { member.voice.setChannel(toChannel).catch(err => { // Do nothing, 99% missing permissions });; }); } }); interaction.reply({ content: "Moved all users to " + toChannel.name, ephemeral: true }); break; case "move": fromChannel = interaction.options.getChannel("from"); toChannel = interaction.options.getChannel("to"); if (toChannel?.guild != interaction.guild || fromChannel?.guild != interaction.guild) { return interaction.reply({ content: "You must specify a voice channel in this server", ephemeral: true }); } fromChannel?.members?.forEach(member => { member.voice?.setChannel(toChannel).catch(err => { // Do nothing, 99% missing permissions });; }); interaction.reply({ content: "Moved all users from " + fromChannel.name + " to " + toChannel.name, ephemeral: true }); break; case "disconnectall": interaction.guild.channels.cache.forEach(channel => { channel.members?.forEach(member => { member.voice.setChannel(null).catch(err => { // Do nothing, 99% missing permissions });; }); interaction.reply({ content: "Disconnected all users", ephemeral: true }); }); break; case "disconnect": channel = interaction.options.getChannel("channel"); if (channel?.guild != interaction.guild) { return interaction.reply({ content: "You must specify a voice channel in this server", ephemeral: true }); } channel?.members?.forEach(member => { member.voice?.setChannel(null).catch(err => { // Do nothing, 99% missing permissions }); }); interaction.reply({ content: "Disconnected all users from " + channel.name, ephemeral: true }); break; } }); client.login(process.env.DISCORD_TOKEN);