toowake

mod-panel.js

Jun 22nd, 2023
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits, PermissionsBitField, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require("discord.js");
  2.  
  3. module.exports = {
  4.     data: new SlashCommandBuilder()
  5.     .setName("mod-panel")
  6.     .setDescription("Moderate a user with this panel")
  7.     .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
  8.     .addUserOption(option => option
  9.         .setName("target")
  10.         .setDescription("the target of the actions")
  11.         .setRequired(true)
  12.     )
  13.     .addStringOption(option => option
  14.         .setName("reason")
  15.         .setDescription("the reason for your action")
  16.         .setRequired(true)
  17.     ),
  18.  
  19.     async execute (interaction, client) {
  20.         const {guild, options} = interaction;
  21.         const target = options.getMember("target");
  22.         const reason = options.getString("reason") || "No Reason given";
  23.  
  24.         if (target === interaction.user) {
  25.             return await interaction.reply({
  26.                 content: "You cant moderate yourself!",
  27.                 ephemeral: true
  28.             })
  29.         }
  30.  
  31.         //timeout row
  32.         const tRow = new ActionRowBuilder()
  33.         .addComponents(
  34.             new ButtonBuilder()
  35.             .setCustomId("1")
  36.             .setLabel("TO 5 Minutes")
  37.             .setEmoji("⛔")
  38.             .setStyle(ButtonStyle.Danger),
  39.             new ButtonBuilder()
  40.             .setCustomId("2")
  41.             .setLabel("TO 10 Minutes")
  42.             .setEmoji("⛔")
  43.             .setStyle(ButtonStyle.Danger),
  44.             new ButtonBuilder()
  45.             .setCustomId("3")
  46.             .setLabel("TO 1 Hour")
  47.             .setEmoji("⛔")
  48.             .setStyle(ButtonStyle.Danger),
  49.             new ButtonBuilder()
  50.             .setCustomId("4")
  51.             .setLabel("TO 1 Day")
  52.             .setEmoji("⛔")
  53.             .setStyle(ButtonStyle.Danger),
  54.             new ButtonBuilder()
  55.             .setCustomId("5")
  56.             .setLabel("TO 1 Week")
  57.             .setEmoji("⛔")
  58.             .setStyle(ButtonStyle.Danger),
  59.         )
  60.  
  61.         //mod row
  62.         const Row = new ActionRowBuilder()
  63.         .addComponents(
  64.             new ButtonBuilder()
  65.             .setCustomId("ban")
  66.             .setLabel("Ban")
  67.             .setEmoji("🔨")
  68.             .setStyle(ButtonStyle.Danger),
  69.             new ButtonBuilder()
  70.             .setCustomId("kick")
  71.             .setLabel("Kick")
  72.             .setEmoji("🔨")
  73.             .setStyle(ButtonStyle.Danger),
  74.             new ButtonBuilder()
  75.             .setCustomId("untimeout")
  76.             .setEmoji("✅")
  77.             .setLabel("Untimeout")
  78.             .setStyle(ButtonStyle.Success),
  79.         )
  80.  
  81.         const embed = new EmbedBuilder()
  82.         .setTitle("Moderation Panel")
  83.         .setDescription(`This is the panel to moderate <@${target.id}>!`)
  84.         .addFields(
  85.             {name: "Name:", value: `${target.username}`, inline: true},
  86.             {name: "User ID:", value: `${target.id}`, inline: true},
  87.             {name: "User:", value: `<@${target.id}>`, inline: true},
  88.             {name: "Avatar URL:", value: `[Avatar](${await target.displayAvatarURL()})`, inline: true},
  89.             {name: "Reason:", value: `${reason}`, inline: false}
  90.         )
  91.         .setThumbnail(await target.displayAvatarURL())
  92.         .setTimestamp()
  93.  
  94.         const msg = await interaction.reply({
  95.             embeds: [embed],
  96.             components: [Row, tRow]
  97.         });
  98.  
  99.         const collector = msg.createMessageComponentCollector();
  100.  
  101.         const embed2 = new EmbedBuilder()
  102.         .setTimestamp()
  103.         .setFooter({ text: `Moderator: ${interaction.user.username}`})
  104.  
  105.         collector.on('collect', async i => {
  106.             if (i.customId === "ban") {
  107.                 if (!i.member.permissions.has(PermissionFlagsBits.BanMembers)) {
  108.                     return await i.reply({
  109.                         content: "You cant **BAN** Members!",
  110.                         ephemeral: true
  111.                     })
  112.                 }
  113.  
  114.                 await interaction.guild.members.ban(target, {reason});
  115.  
  116.                 embed2.setTitle("Ban").setDescription(`You have been banned in ${i.guild.name}! || **Reason:** ${reason}`)
  117.  
  118.                 await target.send({ embeds: [embed2] }).catch(err => {
  119.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  120.                 });;
  121.  
  122.                 await i.reply({ content: `<@${target.id}> has been banned!`, ephemeral: true});
  123.             }
  124.  
  125.             if (i.customId === "untimeout") {
  126.                 if (!i.member.permissions.has(PermissionFlagsBits.ModerateMembers)) return await i.reply({ content: "You dont have the permission to **TIMEOUT** Members!", ephemeral: true})
  127.  
  128.                 await target.timeout(null);
  129.  
  130.                 embed2.setTitle("Untimeout").setDescription(`You have been untimeouted in ${i.guild.name}! || **Reason:** ${reason}`);
  131.  
  132.                 await target.send({ embeds: [embed2] }).catch(err => {
  133.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  134.                 });;
  135.  
  136.                 await i.reply({ content: `<@${target.id}> has been untimeouted!`, ephemeral: true});
  137.             }
  138.  
  139.             if (i.customId === "kick") {
  140.                 if (!i.member.permissions.has(PermissionFlagsBits.KickMembers)) return await i.reply({ content: "You dont have the permission to **KICK** Members!", ephemeral: true});
  141.  
  142.                 await interaction.guild.members.ban(target, {reason});
  143.  
  144.                 embed2.setTitle("Kick").setDescription(`You have been kicked in ${i.guild.name}! || **Reason:** ${reason}`)
  145.  
  146.                 await target.send({ embeds: [embed2] }).catch(err => {
  147.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  148.                 });
  149.  
  150.                 await i.reply({ content: `<@${target.id}> has been kicked!`, ephemeral: true});
  151.                
  152.             }
  153.  
  154.             if (i.customId === "1") {
  155.                 if (!i.member.permissions.has(PermissionFlagsBits.ModerateMembers)) return await i.reply({ content: "You dont have the permission to **TIMEOUT** Members!", ephemeral: true});
  156.  
  157.                 await target.timeout(300000, reason).catch(err => {
  158.                     return i.reply({ content: "There was an Error timeouting this member!", ephemeral: true });
  159.                 });
  160.  
  161.                 embed2.setTitle("Timeout").setDescription(`You have been timeouted for **5 Minutes** || **Reason:** ${reason}`);
  162.  
  163.                 await target.send({ embeds: [embed2] }).catch(err => {
  164.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  165.                 });
  166.  
  167.                
  168.                 await i.reply({ content: `<@${target.id}> has been timeouted for **5 Minutes**`, ephemeral: true});
  169.  
  170.             }
  171.  
  172.             if (i.customId === "2") {
  173.                 if (!i.member.permissions.has(PermissionFlagsBits.ModerateMembers)) return await i.reply({ content: "You dont have the permission to **TIMEOUT** Members!", ephemeral: true});
  174.  
  175.                 await target.timeout(600000, reason).catch(err => {
  176.                     return i.reply({ content: "There was an Error timeouting this member!", ephemeral: true });
  177.                 });
  178.  
  179.                 embed2.setTitle("Timeout").setDescription(`You have been timeouted for **10 Minutes** || **Reason:** ${reason}`);
  180.  
  181.                 await target.send({ embeds: [embed2] }).catch(err => {
  182.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  183.                 });
  184.  
  185.                 await i.reply({ content: `<@${target.id}> has been timeouted for **10 Minutes**`, ephemeral: true});
  186.             }
  187.  
  188.             if (i.customId === "3") {
  189.                 if (!i.member.permissions.has(PermissionFlagsBits.ModerateMembers)) return await i.reply({ content: "You dont have the permission to **TIMEOUT** Members!", ephemeral: true});
  190.  
  191.                 await target.timeout(3600000, reason).catch(err => {
  192.                     return i.reply({ content: "There was an Error timeouting this member!", ephemeral: true });
  193.                 });
  194.  
  195.                 embed2.setTitle("Timeout").setDescription(`You have been timeouted for *1 Hour** || **Reason:** ${reason}`);
  196.  
  197.                 await target.send({ embeds: [embed2] }).catch(err => {
  198.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  199.                 });
  200.  
  201.                 await i.reply({ content: `<@${target.id}> has been timeouted for **1 Hour**`, ephemeral: true});
  202.             }
  203.  
  204.             if (i.customId === "4") {
  205.                 if (!i.member.permissions.has(PermissionFlagsBits.ModerateMembers)) return await i.reply({ content: "You dont have the permission to **TIMEOUT** Members!", ephemeral: true});
  206.  
  207.                 await target.timeout(86400000, reason).catch(err => {
  208.                     return i.reply({ content: "There was an Error timeouting this member!", ephemeral: true });
  209.                 });
  210.  
  211.                 embed2.setTitle("Timeout").setDescription(`You have been timeouted for **1 Day** || **Reason:** ${reason}`);
  212.  
  213.                 await target.send({ embeds: [embed2] }).catch(err => {
  214.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  215.                 });
  216.  
  217.                 await i.reply({ content: `<@${target.id}> has been timeouted for **1 Day**`, ephemeral: true});
  218.             }
  219.  
  220.             if (i.customId === "5") {
  221.                 if (!i.member.permissions.has(PermissionFlagsBits.ModerateMembers)) return await i.reply({ content: "You dont have the permission to **TIMEOUT** Members!", ephemeral: true});
  222.  
  223.                 await target.timeout(604800000, reason).catch(err => {
  224.                     return i.reply({ content: "There was an Error timeouting this member!", ephemeral: true });
  225.                 });
  226.  
  227.                 embed2.setTitle("Timeout").setDescription(`You have been timeouted for **1 Week** || **Reason:** ${reason}`);
  228.  
  229.                 await target.send({ embeds: [embed2] }).catch(err => {
  230.                     return i.reply({ content: "There was an Error sending this user a dm!", ephemeral: true});
  231.                 });
  232.  
  233.                 await i.reply({ content: `<@${target.id}> has been timeouted for **1 Week**`, ephemeral: true});
  234.             }
  235.  
  236.            
  237.         })
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment