250 lines
7.3 KiB
JavaScript
250 lines
7.3 KiB
JavaScript
// 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
|
|
}
|
|
]
|
|
},
|
|
{
|
|
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
|
|
}
|
|
]
|
|
|
|
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.`);
|
|
});
|
|
});
|
|
|
|
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) {
|
|
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
|
|
});
|
|
}
|
|
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 => {
|
|
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
|
|
});
|
|
}
|
|
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
|
|
});;
|
|
});
|
|
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
|
|
});
|
|
}
|
|
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
|
|
});
|
|
});
|
|
interaction.reply({
|
|
content: "Disconnected all users from " + channel.name,
|
|
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;
|
|
}
|
|
});
|
|
|
|
client.login(process.env.DISCORD_TOKEN); |