Advertisement
Zaayd

Private Channel System (Event)

Jul 5th, 2021 (edited)
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const colors = require("colors");
  3. let db = require("quick.db")
  4. module.exports = {
  5.   name:"voiceStateUpdate",
  6.   async execute(oldVoice , newVoice , client) {
  7.     let user = newVoice.guild.member(oldVoice.guild.members.cache.find(userID => userID.id === newVoice.id));
  8.     let channel = await db.fetch(`PrivateCahnnel_[${newVoice.guild.id}]`)
  9.     if(channel === null) return console.log("1".red)
  10.     let category = await db.fetch(`PrivateCategory_[${newVoice.guild.id}]`)
  11.     if(category === null) return console.log("2".red)
  12.     if(!oldVoice.channel && newVoice.channel.id === channel){
  13.       if(newVoice.guild.channels.cache.find(Channel => Channel.name === user.user.username)) return user.send(`**You have already a private channel**`)
  14.       newVoice.guild.channels.create(user.user.username,{
  15.         type:"voice",
  16.         parent:category,
  17.         reason:`Private Channel By: ${user.user.username}`,
  18.         permissionOverwrites:[
  19.           {
  20.             id : newVoice.guild.id,
  21.             deny : ["CONNECT"]
  22.           },
  23.           {
  24.             id : user.id,
  25.             allow : ['CONNECT', 'MANAGE_CHANNELS', 'SPEAK', 'STREAM', 'MUTE_MEMBERS', 'MOVE_MEMBERS', 'VIEW_CHANNEL', 'DEAFEN_MEMBERS']
  26.           }
  27.         ]
  28.       }).then(userChannel => {
  29.         user.voice.setChannel(userChannel.id)
  30.         user.send(`**Sucessflly create a private channel ${userChannel}**`)
  31.       })
  32.       let channelC = newVoice.guild.channels.cache.find(Channel => Channel.id === channel);
  33.       channelC.updateOverwrite(user.id ,
  34.         {
  35.           CONNECT:false,
  36.           VIEW_CHANNEL:true
  37.         }
  38.       )
  39.     } else if(!newVoice.channel){
  40.       if(oldVoice.channel && oldVoice.guild.channels.cache.find(Channel => Channel.name === user.user.username)){
  41.         oldVoice.channel.delete();
  42.         let channelC = newVoice.guild.channels.cache.find(Channel => Channel.id === channel);
  43.         channelC.updateOverwrite(user.id ,
  44.           {
  45.             CONNECT:true,
  46.             VIEW_CHANNEL:true
  47.           }
  48.         )
  49.         user.send(`**Sucessflly delete the private channel**`)
  50.       }
  51.     }
  52.   }
  53. }
  54. /*
  55. Code by Me , 9 9 9 </>#9044
  56. Me Codes Link : https://discord.gg/td3NFBBkGC or https://discord.gg/mecodes
  57. */
  58. /*
  59. Other Link :
  60. Setup Channel : https://pastebin.com/T4x5uZk8
  61. Setup Category : https://pastebin.com/JVg29hvZ
  62. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement