toowake

Guild Info.js

Sep 15th, 2023
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder, EmbedBuilder, ChannelType } = 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 id of the server/guild").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 name = guild.name;
  21.         const id = guild.id;
  22.         const ownerId = guild.ownerId;
  23.         const textChannelCount = guild.channels.cache.filter((channel) => channel.type === ChannelType.GuildText).size;
  24.         const voiceChannelCount = guild.channels.cache.filter((channel) => channel.type === ChannelType.GuildVoice).size;
  25.         const defaultMessage = guild.defaultMessageNotifications;
  26.         const afkTimeout = guild.afkTimeout;
  27.         const created = guild.createdAt;
  28.         const avatar = guild.iconURL();
  29.         const banner = guild.bannerURL()
  30.         const roleCount = guild.roles.cache.size;
  31.         const channels = guild.channels.cache.size;
  32.  
  33.         const text =  `Text: ${textChannelCount}`;
  34.         const voice = `Voice: ${voiceChannelCount}`;
  35.  
  36.  
  37.         const embed = new EmbedBuilder()
  38.         .setTitle(`Guild Information for ${name}`)
  39.         .setThumbnail(`${avatar}`)
  40.         .addFields(
  41.             {name: "Name:", value: `${name}`},
  42.             {name: "ID:", value: `${id}`},
  43.             {name: "Owner ID:", value: `${ownerId}`},
  44.             {name: "Owner Tag:", value: `<@${ownerId}>`},
  45.             {name: "Channel Count:", value: `\n${text} \n${voice} \n\n TOTAL: ${channels}`},
  46.             {name: "Roles:", value: `${roleCount}`},
  47.             {name: "Default Message Perms:", value: `${defaultMessage}`},
  48.             {name: "AFK Timeout:", value: `${afkTimeout}`},
  49.             {name: "Created At:", value: `${created}`},
  50.             {name: "Avatar:", value: `[Link](${avatar})`}
  51.         )
  52.  
  53.         if (banner) {
  54.             embed.addFields({
  55.                 name: "Banner:",
  56.                 value: `[Link](${banner})`
  57.             })
  58.  
  59.             embed.setImage(`${banner}`)
  60.         }
  61.  
  62.         const owner = client.users.cache.get(`${guild.ownerId}`);
  63.  
  64.         if (owner) {
  65.             const ownerEmbed = new EmbedBuilder()
  66.             .setTitle(`Owner Information of ${guild.name}`)
  67.             .setThumbnail(`${owner.displayAvatarURL()}`)
  68.             .addFields(
  69.                 {name: "Name:", value: `${owner.username}`},
  70.                 {name: "ID:", value: `${owner.id}`},
  71.                 {name: "Tag:", value: `${owner}`},
  72.                 {name: "Created Account:", value: `${owner.createdAt}`},
  73.             )
  74.  
  75.             await interaction.reply({
  76.                 embeds: [embed, ownerEmbed]
  77.             })
  78.  
  79.         } else {
  80.             await interaction.reply({
  81.                 embeds: [embed]
  82.             })
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment