ardittristan

Untitled

Dec 4th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const client = new Discord.Client();
  3. const config = require("./config.json");
  4.  
  5.  
  6. client.login(config.token);
  7.  
  8. client.on("ready", () => {
  9.     console.log("Booted");
  10. });
  11.  
  12. // remove empty channels
  13. client.on("voiceStateUpdate", (voiceupdate) => {
  14.     const guild = voiceupdate.guild;
  15.     var categoryChannels = guild.channels.get(config.lobbyId).parent.children.array();
  16.     var emptyChannels = categoryChannels.filter(channel => channel.members.size === 0);
  17.  
  18.     for (i = 0; i < emptyChannels.length; i++) {
  19.         if (emptyChannels[i].id !== config.lobbyId) {
  20.             emptyChannels[i].delete("removing empty channels");
  21.         }
  22.     }
  23. });
  24.  
  25. // commands
  26. client.on("message", (message) => {
  27.     if (!message.content.startsWith(config.prefix) || message.author.bot) return;
  28.    
  29.     const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  30.     const command = args.shift().toLowerCase();
  31.  
  32.     if (message.guild != null) {
  33.         const guild = message.guild;
  34.         const lobbyVc = guild.channels.get(config.lobbyId);
  35.        
  36.         if (message.channel.id === config.commandChatId) {
  37.             // create a vc
  38.             if (command === "createvc") {
  39.                 if (message.member.voiceChannelID === lobbyVc.id) { // checks if the user is in the lobby
  40.                     if (args[0] === "public") {
  41.                         guild.createChannel(message.author.username, "voice").then(createdChannel => {
  42.                             createdChannel.edit({
  43.                                 parent: config.parentId
  44.                             });
  45.                             message.member.setVoiceChannel(createdChannel);
  46.                         });
  47.                     }
  48.                     else
  49.                     if (args[0] === "private") {
  50.                         guild.createChannel(message.author.username, "voice", [{id: guild.id, deny: ["CONNECT"]}])
  51.                         .then(createdChannel => {
  52.                             createdChannel.edit({
  53.                                 parent: config.parentId
  54.                             })
  55.                             // .then(createdChannel.overwritePermissions(message.member.user.id,{'CONNECT':true}))
  56.                             .then(createdChannel => {
  57.                                 message.member.setVoiceChannel(createdChannel);
  58.                             });
  59.                         });
  60.                     }
  61.                     else {
  62.                         message.channel.send("Please specify if the channel is public or private.");
  63.                     }
  64.                 }
  65.                 else {
  66.                     message.channel.send("Please join " + lobbyVc.name + " to create a channel.");
  67.                 }
  68.             }
  69.             else // rename a vc
  70.             if (command === "renamevc") {
  71.                 if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is allowed to rename vc
  72.                     console.log("<" + message.member.id + "> renamed <" + message.member.voiceChannel.name + "> into <" + message.content.slice(config.prefix.length + 9) + ">");
  73.                     message.member.voiceChannel.setName(message.content.slice(config.prefix.length + 9));
  74.                 }
  75.                 else {
  76.                     message.channel.send("You don't have the permission to rename this vc.");
  77.                 }
  78.             }
  79.             else // allow an user
  80.             if (command === "allowuser") {
  81.                 if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
  82.                     if (guild.members.has(args[0])) {
  83.                         guild.channels.get(message.member.voiceChannelID).overwritePermissions(args[0],{"CONNECT":true});
  84.                     }
  85.                     else
  86.                     if (message.mentions.members.first() != undefined) {
  87.                         guild.channels.get(message.member.voiceChannelID).overwritePermissions(message.mentions.members.first().id,{"CONNECT":true});
  88.                     }
  89.                     else {
  90.                         message.channel.send("Please attach an user-id or mention to the command.");
  91.                     }
  92.                 }
  93.                 else {
  94.                     message.channel.send("You are not allowed to allow users in this voice channel.");
  95.                 }
  96.             }
  97.             else // deny user
  98.             if (command === "denyuser") {
  99.                 if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
  100.                     if (guild.members.has(args[0])) {
  101.                         guild.channels.get(message.member.voiceChannelID).overwritePermissions(args[0],{"CONNECT":true});
  102.                     }
  103.                     else
  104.                     if (message.mentions.members.first() != undefined) {
  105.                         guild.channels.get(message.member.voiceChannelID).overwritePermissions(message.mentions.members.first().id,{"CONNECT":true});
  106.                     }
  107.                     else {
  108.                         message.channel.send("Please attach an user-id or mention to the command.");
  109.                     }
  110.                 }
  111.                 else {
  112.                     message.channel.send("You are not allowed to deny users in this voice channel.");
  113.                 }
  114.             }
  115.         }
  116.     }
  117. });
Advertisement
Add Comment
Please, Sign In to add comment