From 0e0079dd3b9ab3f628ff02cefaf140d0934a602c Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Sat, 3 Apr 2021 20:10:31 -0500 Subject: [PATCH] Add member count channel creation command --- index.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/index.js b/index.js index c715252..135beef 100644 --- a/index.js +++ b/index.js @@ -66,6 +66,9 @@ client.on("message", async message => { case `${prefix}iss`: locateISS(message); break; + case `${prefix}membercountchannel`: + memberCountChannelCreate(message); + break; } if (message.content.toLowerCase().startsWith(`${prefix}bulkdelete`)) { @@ -206,6 +209,54 @@ async function kulboardCreate(message) { }); } +async function memberCountChannelCreate(message) { + if (!message.member.hasPermission("ADMINISTRATOR")) { + message.reply("you do not have admin permissions!"); + return; + } + collection.findOne({ guild_id: message.guild.id }, (error, result) => { + if (error) { + console.error; + } + if (result.member_count_channel_id) { + memberCountChannel = result.member_count_channel_id; + if (message.guild.channels.cache.get(memberCountChannel)) { + message.reply('member count channel already exists!'); + } else { + // Create "#bot-logs" text channel to track message deletes, edits, and channel creations + message.guild.channels.create(`Members: ${message.guild.memberCount}`, { + type: 'voice', + // Remove view permissions from "@everyone" + permissionOverwrites: [{ + id: message.guild.id, + allow: ['VIEW_CHANNEL'], + deny: ['CONNECT'], + }] + }).then(channel => { + // Add the ID of the "#bot-logs" channel to the database + message.reply(`channel ${channel} created!`) + collection.updateOne({ guild_id: message.guild.id }, { $set: { "member_count_channel_id": `${channel.id}` } }); + }).catch(console.error); + } + } else { + // Create "#bot-logs" text channel to track message deletes, edits, and channel creations + message.guild.channels.create(`Members: ${message.guild.memberCount}`, { + type: 'voice', + // Remove view permissions from "@everyone" + permissionOverwrites: [{ + id: message.guild.id, + allow: ['VIEW_CHANNEL'], + deny: ['CONNECT'], + }] + }).then(channel => { + // Add the ID of the "#bot-logs" channel to the database + message.reply(`channel ${channel} created!`) + collection.updateOne({ guild_id: message.guild.id }, { $set: { "member_count_channel_id": `${channel.id}` } }); + }).catch(console.error); + } + }); +} + async function userInfo(message) { if (!message.content.split(" ")[1]) { message.reply("query must contain at least 3 characters!")