ardittristan

Untitled

Dec 4th, 2018
69
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. client.login(config.token);
  6.  
  7. client.on("ready", () => {
  8.     console.log("Booted");
  9. });
  10.  
  11. // commands
  12. client.on("message", (message) => {
  13.     if (!message.content.startsWith(config.prefix) || message.author.bot) return;
  14.    
  15.     const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  16.     const command = args.shift().toLowerCase();
  17.     const guild = message.guild;
  18.     const lobbyVc = guild.channels.get(config.lobbyId);
  19.    
  20.     // create a vc
  21.     if (command === "createvc") {
  22.         if (message.member.voiceChannelID === lobbyVc.id) { // checks if the user is in the lobby
  23.             if (args[0] === "public") {
  24.                 guild.createChannel(message.author.username, "voice").then(createdChannel => {
  25.                     createdChannel.edit({
  26.                         parent: config.parentId
  27.                     });
  28.                     message.member.setVoiceChannel(createdChannel);
  29.                 });
  30.             }
  31.             else
  32.             if (args[0] === "private") {
  33.                 guild.createChannel(message.author.username, "voice", [{id: guild.id, deny: ["CONNECT"]}]).then(createdChannel => {
  34.                     createdChannel.edit({
  35.                         parent: config.parentId
  36.                     });
  37.                     message.member.setVoiceChannel(createdChannel);
  38.                 });
  39.             }
  40.             else {
  41.                 message.channel.send("Please specify if the channel is public or private.");
  42.             }
  43.         }
  44.         else {
  45.             message.channel.send("Please join " + lobbyVc.name + " to create a channel.");
  46.         }
  47.     }
  48.     else // rename a vc
  49.     if (command === "renamevc") {
  50.         if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is allowed to rename vc
  51.             console.log("<" + message.member.id + "> renamed <" + message.member.voiceChannel.name + "> into <" + message.content.slice(config.prefix.length + 9) + ">");
  52.             message.member.voiceChannel.setName(message.content.slice(config.prefix.length + 9));
  53.         }
  54.         else {
  55.             message.channel.send("You don't have the permission to rename this vc.");
  56.         }
  57.     }
  58.     else // allow an user
  59.     if (command === "allowuser") {
  60.         if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
  61.             if (guild.members.has(args[0])) {
  62.                 guild.channels.get(message.member.voiceChannelID).overwritePermissions(args[0],{"CONNECT":true});
  63.             }
  64.             else
  65.             if (message.mentions.members.first() != undefined) {
  66.                 guild.channels.get(message.member.voiceChannelID).overwritePermissions(message.mentions.members.first().id,{"CONNECT":true});
  67.             }
  68.             else {
  69.                 message.channel.send("Please attach an user-id or mention to the command.");
  70.             }
  71.         }
  72.         else {
  73.             message.channel.send("You are not allowed to allow users in this voice channel.");
  74.         }
  75.     }
  76.     else // disallow user
  77.     if (command === "disallowuser") {
  78.         if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
  79.             if (guild.members.has(args[0])) {
  80.                 guild.channels.get(message.member.voiceChannelID).overwritePermissions(args[0],{"CONNECT":true});
  81.             }
  82.             else
  83.             if (message.mentions.members.first() != undefined) {
  84.                 guild.channels.get(message.member.voiceChannelID).overwritePermissions(message.mentions.members.first().id,{"CONNECT":true});
  85.             }
  86.             else {
  87.                 message.channel.send("Please attach an user-id or mention to the command.");
  88.             }
  89.         }
  90.         else {
  91.             message.channel.send("You are not allowed to deny users in this voice channel.");
  92.         }
  93.     }
  94. });
Advertisement
Add Comment
Please, Sign In to add comment