Advertisement
spiralvibes

Made By ZayDocs | Maverick Team

Oct 14th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const {
  2.   ApplicationCommandType,
  3.   ApplicationCommandOptionType,
  4.   EmbedBuilder,
  5.   ChannelType,
  6. } = require('discord.js');
  7. const logSchema = require(`${process.cwd()}/src/database/LogChannel.js`);
  8.  
  9. module.exports = {
  10.   name: 'setup-logs',
  11.   description: 'Setup and manage the logging system for your server.',
  12.   usage: '/setup-logs <enable/disable> [channelId]',
  13.   category: 'Admin',
  14.   userPerms: ['ManageChannels'],
  15.   botPerms: [],
  16.   cooldown: 5,
  17.   guildOnly: false,
  18.   options: [
  19.     {
  20.       name: 'enable',
  21.       description: 'Enable the logging system and set the log channel.',
  22.       type: ApplicationCommandOptionType.Subcommand,
  23.       options: [
  24.         {
  25.           name: 'channelid',
  26.           description: 'The ID of the channel to set as the log channel.',
  27.           type: ApplicationCommandOptionType.String,
  28.           required: true,
  29.         },
  30.       ],
  31.     },
  32.     {
  33.       name: 'disable',
  34.       description: 'Disable the logging system.',
  35.       type: ApplicationCommandOptionType.Subcommand,
  36.     },
  37.   ],
  38.   run: async (client, interaction) => {
  39.     const subCommand = interaction.options.getSubcommand();
  40.     const guildId = interaction.guildId;
  41.  
  42.     try {
  43.       switch (subCommand) {
  44.         case 'enable': {
  45.           const channelId = interaction.options.getString('channelid');
  46.           const channel = await client.channels.fetch(channelId);
  47.  
  48.           if (!channel || (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.GuildVoice)) {
  49.             const errorEmbed = new EmbedBuilder()
  50.               .setColor('#FF0000')
  51.               .setAuthor({
  52.                 name: 'Error 🚫',
  53.                 iconURL: client.user.displayAvatarURL(),
  54.               })
  55.               .setDescription('You must specify a valid text or voice channel to set as the log channel.')
  56.               .setFooter({
  57.                 text: 'CubeCloud Logging',
  58.                 iconURL: client.user.displayAvatarURL(),
  59.               });
  60.  
  61.             return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
  62.           }
  63.  
  64.           await logSchema.findOneAndUpdate(
  65.             { Guild: guildId },
  66.             {
  67.               Channel: channel.id,
  68.               Events: [
  69.                 "MESSAGE_DELETE",
  70.                 "MESSAGE_EDIT",
  71.                 "PROFILE_PICTURE_UPDATE",
  72.                 "VOICE_CHANNEL_JOIN",
  73.                 "VOICE_CHANNEL_LEAVE",
  74.                 "USER_BAN",
  75.                 "USER_UNBAN",
  76.                 "ROLE_CREATE",
  77.                 "ROLE_DELETE",
  78.                 "CHANNEL_CREATE",
  79.                 "CHANNEL_DELETE",
  80.               ],
  81.               CreatedAt: new Date(),
  82.             },
  83.             { upsert: true }
  84.           );
  85.  
  86.           const enableEmbed = new EmbedBuilder()
  87.             .setColor('#0000FF')
  88.             .setAuthor({
  89.               name: 'Logging System Enabled ✅',
  90.               iconURL: client.user.displayAvatarURL(),
  91.             })
  92.             .setDescription(`Logging system has been enabled and set to <#${channel.id}>.`)
  93.             .setFooter({
  94.               text: 'CubeCloud Logging',
  95.               iconURL: client.user.displayAvatarURL(),
  96.             });
  97.  
  98.           return interaction.reply({ embeds: [enableEmbed] });
  99.         }
  100.  
  101.         case 'disable': {
  102.           await logSchema.findOneAndUpdate(
  103.             { Guild: guildId },
  104.             { $unset: { Channel: "" }, $set: { Events: [], loggingEnabled: false } }
  105.           );
  106.  
  107.           const disableEmbed = new EmbedBuilder()
  108.             .setColor('#FF0000')
  109.             .setAuthor({
  110.               name: 'Logging System Disabled ❌',
  111.               iconURL: client.user.displayAvatarURL(),
  112.             })
  113.             .setDescription('Logging system has been disabled.')
  114.             .setFooter({
  115.               text: 'CubeCloud Logging',
  116.               iconURL: client.user.displayAvatarURL(),
  117.             });
  118.  
  119.           return interaction.reply({ embeds: [disableEmbed] });
  120.         }
  121.  
  122.         default: {
  123.           const invalidEmbed = new EmbedBuilder()
  124.             .setColor('#FF0000')
  125.             .setAuthor({
  126.               name: 'Error 🚫',
  127.               iconURL: client.user.displayAvatarURL(),
  128.             })
  129.             .setDescription('Invalid subcommand.')
  130.             .setFooter({
  131.               text: 'CubeCloud Logging',
  132.               iconURL: client.user.displayAvatarURL(),
  133.             });
  134.  
  135.           return interaction.reply({ embeds: [invalidEmbed], ephemeral: true });
  136.         }
  137.       }
  138.     } catch (error) {
  139.       console.error(error);
  140.       const errorEmbed = new EmbedBuilder()
  141.         .setColor('#FF0000')
  142.         .setAuthor({
  143.           name: 'Error 🚫',
  144.           iconURL: client.user.displayAvatarURL(),
  145.         })
  146.         .setDescription('An error occurred while processing the command.')
  147.         .setFooter({
  148.           text: 'CubeCloud Logging',
  149.           iconURL: client.user.displayAvatarURL(),
  150.         });
  151.  
  152.       return interaction.reply({ embeds: [errorEmbed], ephemeral: true });
  153.     }
  154.   },
  155. };
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement