Add dispersal commands :trol:
This commit is contained in:
parent
8efc569cea
commit
5ffe1ab8d7
88
index.js
88
index.js
|
@ -68,6 +68,24 @@ client.on('ready', () => {
|
||||||
required: true
|
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 => {
|
client.on('interactionCreate', async interaction => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
switch (interaction.commandName) {
|
switch (interaction.commandName) {
|
||||||
|
@ -92,6 +115,10 @@ client.on('interactionCreate', async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!checkType(toChannel.type)) return interaction.reply({
|
||||||
|
content: "You must specify a voice channel",
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
interaction.guild.channels.cache.forEach(channel => {
|
interaction.guild.channels.cache.forEach(channel => {
|
||||||
if (channel?.type == Discord.ChannelType.GuildVoice) {
|
if (channel?.type == Discord.ChannelType.GuildVoice) {
|
||||||
channel.members.forEach(member => {
|
channel.members.forEach(member => {
|
||||||
|
@ -115,6 +142,10 @@ client.on('interactionCreate', async interaction => {
|
||||||
ephemeral: true
|
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 => {
|
fromChannel?.members?.forEach(member => {
|
||||||
member.voice?.setChannel(toChannel).catch(err => {
|
member.voice?.setChannel(toChannel).catch(err => {
|
||||||
// Do nothing, 99% missing permissions
|
// Do nothing, 99% missing permissions
|
||||||
|
@ -146,6 +177,10 @@ client.on('interactionCreate', async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!checkType(channel.type)) return interaction.reply({
|
||||||
|
content: "You must specify a voice channel",
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
channel?.members?.forEach(member => {
|
channel?.members?.forEach(member => {
|
||||||
member.voice?.setChannel(null).catch(err => {
|
member.voice?.setChannel(null).catch(err => {
|
||||||
// Do nothing, 99% missing permissions
|
// Do nothing, 99% missing permissions
|
||||||
|
@ -156,6 +191,59 @@ client.on('interactionCreate', async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue