toowake

guild-info.js

Oct 27th, 2023
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder, EmbedBuilder, ChannelType, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, ActionRowBuilder, ComponentType } = require("discord.js");
  2. module.exports = {
  3.     data: new SlashCommandBuilder()
  4.     .setName("guild-info")
  5.     .setDescription("Get information about a guild")
  6.     .addStringOption(option => option.setName("guild-id").setDescription("The guild/server id").setRequired(true)),
  7.  
  8.     async execute (interaction, client) {
  9.         const {options} = interaction;
  10.         const guildID = options.getString("guild-id");
  11.         const guild = await client.guilds.cache.get(guildID)
  12.  
  13.         if (!guild) {
  14.             await interaction.reply({
  15.                 content: `I cannot find a guild with the id ${guildID}!`,
  16.                 ephemeral: true
  17.             })
  18.         }
  19.  
  20.         const startEmbed = new EmbedBuilder()
  21.         .setDescription(`As i can see you want info about \`${guildID}\`, choose a option below!`)
  22.         .setColor("White")
  23.  
  24.         const name = guild.name;
  25.         const id = guild.id;
  26.         const ownerId = guild.ownerId;
  27.         const textChannelCount = guild.channels.cache.filter((channel) => channel.type === ChannelType.GuildText).size;
  28.         const voiceChannelCount = guild.channels.cache.filter((channel) => channel.type === ChannelType.GuildVoice).size;
  29.         const defaultMessage = guild.defaultMessageNotifications;
  30.         const afkTimeout = guild.afkTimeout;
  31.         const created = guild.createdAt;
  32.         const avatar = guild.iconURL();
  33.         const banner = guild.bannerURL();
  34.         const roleCount = guild.roles.cache.size;
  35.         const channels = guild.channels.cache.size;
  36.         const totalMembers = guild.memberCount;
  37.         const botMembers = guild.members.cache.filter(member => member.user.bot).size;
  38.         const humanMembers = totalMembers - botMembers;
  39.         const memberText = `Bots: ${botMembers} \nHumans: ${humanMembers} \n\n**TOTAL:** ${totalMembers}`
  40.  
  41.         const text =  `Text: ${textChannelCount}`;
  42.         const voice = `Voice: ${voiceChannelCount}`;
  43.  
  44.         /*const mods = guild.members.forEach(async member => {
  45.             if (member.permissions.has(PermissionFlagsBits.ModerateMembers)) {
  46.                 return `\n${member}`
  47.             }
  48.         })
  49.  
  50.         const admin = guild.members.forEach(async member => {
  51.             if (member.permissions.has(PermissionFlagsBits.ModerateMembers)) {
  52.                 return `\n${member}`
  53.             }
  54.         })*/
  55.  
  56.  
  57.         const embed = new EmbedBuilder()
  58.         .setTitle(`Guild Information for ${name}`)
  59.         .setThumbnail(`${avatar}`)
  60.         .addFields(
  61.             {name: "Name:", value: `${name}`},
  62.             {name: "ID:", value: `${id}`},
  63.             {name: "Owner ID:", value: `${ownerId}`},
  64.             {name: "Owner Tag:", value: `<@${ownerId}>`},
  65.             {name: "Channel Count:", value: `\n${text} \n${voice} \n\n TOTAL: ${channels}`},
  66.             {name: "Roles:", value: `${roleCount}`},
  67.             {name: "Default Message Perms:", value: `${defaultMessage}`},
  68.             {name: "AFK Timeout:", value: `${afkTimeout}`},
  69.             {name: "Created At:", value: `${created}`},
  70.             {name: "Avatar:", value: `[Link](${avatar})`},
  71.             {name: "Membercount:", value: memberText},
  72.             /*{name: "Staff:", value: `Admins: ${admin} \nModerators: ${mods}`}*/
  73.         )
  74.  
  75.         if (banner) {
  76.             embed.addFields({
  77.                 name: "Banner:",
  78.                 value: `[Link](${banner})`
  79.             })
  80.  
  81.             embed.setImage(`${banner}`)
  82.         }
  83.  
  84.         const owner = client.users.cache.get(`${guild.ownerId}`);
  85.  
  86.         function channelsD(type) {
  87.             const channels = guild.channels.cache.filter((x) => x.type === type).map((channel) => `<#${channel.id}>`).join(', ')
  88.  
  89.             if (!channels) {
  90.                 return "No channels"
  91.             } else {
  92.                 if (channels.length >= 1024) {
  93.                     return "Too much channels to show!"
  94.                 } else {
  95.                     return channels
  96.                 }
  97.             }
  98.         }
  99.  
  100.         function countC(channelType) {
  101.             let count = 0;
  102.             const channels = guild.channels.cache.filter((x) => x.type === channelType).size;
  103.  
  104.             return channels
  105.         }
  106.        
  107.         const channelEmbed = new EmbedBuilder()
  108.         .setTitle("Channel Infos")
  109.         .setColor("White")
  110.         .addFields(
  111.             {name: "Channel Count:", value: `TOTAL: ${guild.channels.cache.size}`},
  112.             {name: `${countC(ChannelType.GuildText)} Text Channels:`, value: `${channelsD(ChannelType.GuildText)}`},
  113.             {name: `${countC(ChannelType.GuildVoice)} Voice Channels:`, value: `${channelsD(ChannelType.GuildVoice)}`},
  114.             {name: `${countC(ChannelType.GuildAnnouncement)} Announcement Channels:`, value: `${channelsD(ChannelType.GuildAnnouncement)}`},
  115.             {name: `${countC(ChannelType.GuildDirectory)} Directory Channels:`, value: `${channelsD(ChannelType.GuildDirectory)}`},
  116.             {name: `${countC(ChannelType.GuildStageVoice)} Stage Voice Channels:`, value: `${channelsD(ChannelType.GuildStageVoice)}`},
  117.             {name: `${countC(ChannelType.PublicThread)} Public Threads:`, value: `${channelsD(ChannelType.PublicThread)}`},
  118.             {name: `${countC(ChannelType.PrivateThread)} Private Threads:`, value: `${channelsD(ChannelType.PrivateThread)}`},
  119.             {name: `${countC(ChannelType.GuildForum)} Forum Channels:`, value: `${channelsD(ChannelType.GuildForum)}`},
  120.             {name: `${countC(ChannelType.AnnouncementThread)} Announcement Threads:`, value: `${channelsD(ChannelType.AnnouncementThread)}`}
  121.         )
  122.  
  123.         const select = new StringSelectMenuBuilder()
  124.         .setCustomId("guild")
  125.         .setPlaceholder("Choose the info you want to get")
  126.         .addOptions(
  127.             new StringSelectMenuOptionBuilder()
  128.             .setLabel("Basic Info")
  129.             .setDescription(`Get basic info about the guild ${guild.name}`)
  130.             .setValue("basic-info"),
  131.  
  132.             new StringSelectMenuOptionBuilder()
  133.             .setLabel("Channel Info")
  134.             .setDescription(`Get all information about the channels of ${guild.name}`)
  135.             .setValue("channel-info"),
  136.         )
  137.  
  138.         if (owner) {
  139.  
  140.             const ownerEmbed = new EmbedBuilder()
  141.             .setTitle(`Owner Information of ${guild.name}`)
  142.             .setThumbnail(`${owner.displayAvatarURL()}`)
  143.             .addFields(
  144.                 {name: "Name:", value: `${owner.username}`},
  145.                 {name: "ID:", value: `${owner.id}`},
  146.                 {name: "Tag:", value: `${owner}`},
  147.                 {name: "Created Account:", value: `${owner.createdAt}`},
  148.             )
  149.  
  150.             const row = new ActionRowBuilder()
  151.             .addComponents(select)
  152.  
  153.             select.addOptions(
  154.                 new StringSelectMenuOptionBuilder()
  155.                 .setLabel("Owner Info")
  156.                 .setDescription(`Get all information about ${owner.username}`)
  157.                 .setValue("owner-info")
  158.             )
  159.  
  160.             const msg = await interaction.reply({
  161.                 embeds: [startEmbed],
  162.                 components: [row]
  163.             })
  164.  
  165.             const collector = await msg.createMessageComponentCollector();
  166.            
  167.             collector.on("collect", async (i) => {
  168.                 if (i.user.id !== interaction.user.id) {
  169.                     await interaction.reply({
  170.                         content: "Sorry, you are not allowed to use these buttons!",
  171.                         ephemeral: true
  172.                     }).catch(err => {return;})
  173.                 } else {
  174.  
  175.                     if (i.values[0] === "channel-info") {
  176.                         await i.reply({ embeds: [channelEmbed], ephemeral: true})
  177.                     }
  178.    
  179.                     if (i.values[0] === "basic-info") {
  180.                         await i.reply({ embeds: [embed], ephemeral: true})
  181.                     }
  182.    
  183.                     if (i.values[0] === "owner-info") {
  184.                         await i.reply({ embeds: [ownerEmbed], ephemeral: true})
  185.                     }
  186.  
  187.                 }
  188.             })
  189.  
  190.         } else {
  191.             const row = new ActionRowBuilder().addComponents(select)
  192.  
  193.             const msg = await interaction.reply({
  194.                 embeds: [startEmbed],
  195.                 components: [row]
  196.             })
  197.  
  198.             const collector = await msg.createMessageComponentCollector({ componentType: ComponentType.StringSelect });
  199.            
  200.             collector.on("collect", async (i) => {
  201.                 if (i.user.id !== interaction.user.id) {
  202.                     await i.reply({
  203.                         content: "Sorry, you are not allowed to use these buttons!",
  204.                         ephemeral: true
  205.                     }).catch(err => {return;})
  206.                 } else {
  207.                     if (i.values[0] === "channel-info") {
  208.                         await i.reply({ embeds: [channelEmbed], ephemeral: true})
  209.                     }
  210.    
  211.                     if (i.values[0] === "basic-info") {
  212.                         await i.reply({ embeds: [embed], ephemeral: true})
  213.                     }
  214.                 }
  215.             })
  216.         }
  217.     }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment