Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const client = new Discord.Client();
- const config = require("./config.json");
- client.login(config.token);
- client.on("ready", () => {
- console.log("Booted");
- });
- // remove empty channels
- client.on("voiceStateUpdate", (voiceupdate) => {
- const guild = voiceupdate.guild;
- var categoryChannels = guild.channels.get(config.lobbyId).parent.children.array();
- var emptyChannels = categoryChannels.filter(channel => channel.members.size === 0);
- for (i = 0; i < emptyChannels.length; i++) {
- if (emptyChannels[i].id !== config.lobbyId) {
- emptyChannels[i].delete("removing empty channels");
- }
- }
- });
- // commands
- client.on("message", (message) => {
- if (!message.content.startsWith(config.prefix) || message.author.bot) return;
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- if (message.guild != null) {
- const guild = message.guild;
- const lobbyVc = guild.channels.get(config.lobbyId);
- if (message.channel.id === config.commandChatId) {
- // create a vc
- if (command === "createvc") {
- if (message.member.voiceChannelID === lobbyVc.id) { // checks if the user is in the lobby
- if (args[0] === "public") {
- guild.createChannel(message.author.username, "voice").then(createdChannel => {
- createdChannel.edit({
- parent: config.parentId
- });
- message.member.setVoiceChannel(createdChannel);
- });
- }
- else
- if (args[0] === "private") {
- guild.createChannel(message.author.username, "voice", [{id: guild.id, deny: ["CONNECT"]}])
- .then(createdChannel => {
- createdChannel.edit({
- parent: config.parentId
- })
- // .then(createdChannel.overwritePermissions(message.member.user.id,{'CONNECT':true}))
- .then(createdChannel => {
- message.member.setVoiceChannel(createdChannel);
- });
- });
- }
- else {
- message.channel.send("Please specify if the channel is public or private.");
- }
- }
- else {
- message.channel.send("Please join " + lobbyVc.name + " to create a channel.");
- }
- }
- else // rename a vc
- if (command === "renamevc") {
- if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is allowed to rename vc
- console.log("<" + message.member.id + "> renamed <" + message.member.voiceChannel.name + "> into <" + message.content.slice(config.prefix.length + 9) + ">");
- message.member.voiceChannel.setName(message.content.slice(config.prefix.length + 9));
- }
- else {
- message.channel.send("You don't have the permission to rename this vc.");
- }
- }
- else // allow an user
- if (command === "allowuser") {
- if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
- if (guild.members.has(args[0])) {
- guild.channels.get(message.member.voiceChannelID).overwritePermissions(args[0],{"CONNECT":true});
- }
- else
- if (message.mentions.members.first() != undefined) {
- guild.channels.get(message.member.voiceChannelID).overwritePermissions(message.mentions.members.first().id,{"CONNECT":true});
- }
- else {
- message.channel.send("Please attach an user-id or mention to the command.");
- }
- }
- else {
- message.channel.send("You are not allowed to allow users in this voice channel.");
- }
- }
- else // deny user
- if (command === "denyuser") {
- if (message.member.voiceChannel.parent.id === config.parentId && message.member.voiceChannelID !== lobbyVc.id) { //checks if user is in a modifyable voice channel
- if (guild.members.has(args[0])) {
- guild.channels.get(message.member.voiceChannelID).overwritePermissions(args[0],{"CONNECT":true});
- }
- else
- if (message.mentions.members.first() != undefined) {
- guild.channels.get(message.member.voiceChannelID).overwritePermissions(message.mentions.members.first().id,{"CONNECT":true});
- }
- else {
- message.channel.send("Please attach an user-id or mention to the command.");
- }
- }
- else {
- message.channel.send("You are not allowed to deny users in this voice channel.");
- }
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment