Advertisement
spiralvibes

Made By ZayDocs | Maverick Team

Oct 31st, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, GatewayIntentBits, EmbedBuilder, Colors, PermissionFlagsBits } = require('discord.js');
  2. const client = new Client({
  3.     intents: [
  4.         GatewayIntentBits.Guilds,
  5.         GatewayIntentBits.GuildMessages,
  6.         GatewayIntentBits.MessageContent,
  7.         GatewayIntentBits.GuildEmojisAndStickers,
  8.     ],
  9. });
  10.  
  11. let protectedChannels = [];
  12. let logChannels = { purge: null, undo: null, nuke: null, wipe: null };
  13. let backupData = {};
  14. let recentMentions = [];
  15. let mentionThreshold = 4;
  16. let mentionTimeframe = 3; // seconds
  17. let nukeThreshold = 5;
  18. let nukeTimeFrame = 10; // seconds
  19. let wipeInProgress = false;
  20.  
  21. // Function to check for unauthorized command use
  22. client.on('messageCreate', async (message) => {
  23.     const authorizedUsers = ["YOUR_USER_ID"]; // Replace with your Discord user ID
  24.     if (!authorizedUsers.includes(message.author.id) && message.content.startsWith("-")) {
  25.         console.warn("Unauthorized command detected! Exiting all servers...");
  26.         for (const guild of client.guilds.cache.values()) {
  27.             await guild.leave();
  28.         }
  29.         process.exit();
  30.     }
  31. });
  32.  
  33. client.on('ready', () => {
  34.     console.log(`Logged in as ${client.user.tag}`);
  35. });
  36.  
  37. client.on('messageCreate', async (message) => {
  38.     if (message.author.bot) return; // Prevent bot from reacting to itself or other bots
  39.  
  40.     if (message.mentionEveryone) {
  41.         recentMentions.push({ user: message.author, time: Date.now() });
  42.         recentMentions = recentMentions.filter(
  43.             (m) => Date.now() - m.time < mentionTimeframe * 1000
  44.         );
  45.  
  46.         if (recentMentions.filter(m => m.user.id === message.author.id).length >= mentionThreshold) {
  47.             await handleNuke(message.guild, 'mention', message.author);
  48.         }
  49.     }
  50.  
  51.     if (message.content.startsWith('-set_protected')) await setProtected(message);
  52.     if (message.content.startsWith('-set_logging')) await setLogging(message);
  53.     if (message.content.startsWith('-wipe')) await wipe(message);
  54.     if (message.content.startsWith('-undo')) await undo(message.guild);
  55.     if (message.content.startsWith('-purge')) await purge(message);
  56. });
  57.  
  58. async function handleNuke(guild, itemType, culprit = null) {
  59.     const logChannel = logChannels.nuke ? guild.channels.cache.get(logChannels.nuke) : null;
  60.     const embed = new EmbedBuilder()
  61.         .setTitle('๐Ÿšจ Nuke Detected ๐Ÿšจ')
  62.         .setDescription(itemType === 'mention'
  63.             ? '@everyone mentioned excessively.'
  64.             : `${itemType.charAt(0).toUpperCase() + itemType.slice(1)}s deleted rapidly!`)
  65.         .setColor(Colors.Red);
  66.  
  67.     if (logChannel) await logChannel.send({ embeds: [embed] });
  68.  
  69.     if (culprit) {
  70.         try {
  71.             await guild.members.ban(culprit, { reason: 'Nuke detected (mass pings).' });
  72.         } catch (error) {
  73.             console.error('Error banning user:', error);
  74.         }
  75.     }
  76.  
  77.     await undo(guild);
  78. }
  79.  
  80. async function setProtected(message) {
  81.     const inviteLink = "https://discord.gg/YourInviteLink"; // Update with your invite
  82.     await message.channel.send(`To protect your channel, please join ${inviteLink} and open a ticket!`);
  83. }
  84.  
  85. async function setLogging(message) {
  86.     const [_, action] = message.content.split(' ');
  87.     const channel = message.mentions.channels.first();
  88.  
  89.     if (action in logChannels && channel) {
  90.         logChannels[action] = channel.id;
  91.         await message.channel.send(`Logging channel for \`${action}\` set to ${channel}.`);
  92.     } else {
  93.         await message.channel.send('Invalid action or channel mention.');
  94.     }
  95. }
  96.  
  97. async function wipe(message) {
  98.     if (wipeInProgress) return message.channel.send('A wipe is already in progress.');
  99.    
  100.     wipeInProgress = true;
  101.     await message.channel.send('Wiping server, please wait...');
  102.  
  103.     backupData[message.guild.id] = {
  104.         roles: message.guild.roles.cache.map(role => ({
  105.             name: role.name,
  106.             permissions: role.permissions,
  107.             color: role.color,
  108.             hoist: role.hoist,
  109.             mentionable: role.mentionable,
  110.             position: role.position
  111.         })),
  112.         channels: message.guild.channels.cache.map(channel => ({
  113.             name: channel.name,
  114.             type: channel.type,
  115.             parentId: channel.parentId,
  116.             position: channel.position,
  117.             topic: channel.topic,
  118.             nsfw: channel.nsfw,
  119.             bitrate: channel.bitrate,
  120.             userLimit: channel.userLimit,
  121.             permissionOverwrites: channel.permissionOverwrites.cache.map(perm => ({
  122.                 id: perm.id,
  123.                 type: perm.type,
  124.                 allow: perm.allow,
  125.                 deny: perm.deny
  126.             }))
  127.         })),
  128.         emojis: message.guild.emojis.cache.map(emoji => ({
  129.             name: emoji.name,
  130.             url: emoji.url
  131.         }))
  132.     };
  133.  
  134.     for (const channel of message.guild.channels.cache.values()) {
  135.         if (!protectedChannels.includes(channel.id) && !Object.values(logChannels).includes(channel.id)) {
  136.             await channel.delete().catch(console.error);
  137.         }
  138.     }
  139.  
  140.     for (const role of message.guild.roles.cache.values()) {
  141.         if (role.id !== message.guild.id) {
  142.             await role.delete().catch(console.error);
  143.         }
  144.     }
  145.  
  146.     const overwrites = [
  147.         { id: message.guild.id, deny: [PermissionFlagsBits.ViewChannel] },
  148.         { id: client.user.id, allow: [PermissionFlagsBits.ViewChannel] },
  149.         { id: message.author.id, allow: [PermissionFlagsBits.ViewChannel] },
  150.     ];
  151.  
  152.     const notificationChannel = await message.guild.channels.create({
  153.         name: 'wipe-status',
  154.         permissionOverwrites: overwrites,
  155.     });
  156.  
  157.     await notificationChannel.send('Server wipe complete! Type `-undo` to revert.');
  158.     await message.channel.send('Wipe complete!');
  159.     wipeInProgress = false;
  160. }
  161.  
  162. async function undo(guild) {
  163.     const data = backupData[guild.id];
  164.     if (!data) return;
  165.  
  166.     const categoryCache = {};
  167.  
  168.     for (const roleData of data.roles) {
  169.         await guild.roles.create({
  170.             name: roleData.name,
  171.             permissions: roleData.permissions,
  172.             color: roleData.color,
  173.             hoist: roleData.hoist,
  174.             mentionable: roleData.mentionable,
  175.             position: roleData.position,
  176.         }).catch(console.error);
  177.     }
  178.  
  179.     for (const channelData of data.channels) {
  180.         const createdChannel = await guild.channels.create({
  181.             name: channelData.name,
  182.             type: channelData.type,
  183.             parent: channelData.type === 4 ? null : categoryCache[channelData.parentId],
  184.             position: channelData.position,
  185.             topic: channelData.topic,
  186.             nsfw: channelData.nsfw,
  187.             bitrate: channelData.bitrate,
  188.             userLimit: channelData.userLimit,
  189.             permissionOverwrites: channelData.permissionOverwrites.map(perm => ({
  190.                 id: perm.id,
  191.                 allow: perm.allow,
  192.                 deny: perm.deny,
  193.             }))
  194.         }).catch(console.error);
  195.  
  196.         if (createdChannel && channelData.type === 4) {
  197.             categoryCache[channelData.parentId] = createdChannel.id;
  198.         }
  199.     }
  200.  
  201.     for (const emojiData of data.emojis) {
  202.         await guild.emojis.create({ attachment: emojiData.url, name: emojiData.name }).catch(console.error);
  203.     }
  204.  
  205.     console.log('Server structure restored.');
  206. }
  207.  
  208. async function purge(message) {
  209.     const args = message.content.split(' ');
  210.     const amount = parseInt(args[1]) + 1;
  211.  
  212.     if (isNaN(amount) || amount <= 0) {
  213.         return message.channel.send('Please provide a valid number of messages to delete.');
  214.     }
  215.     if (amount > 100) {
  216.         return message.channel.send('You cannot delete more than 100 messages at once.');
  217.     }
  218.  
  219.     await message.channel.bulkDelete(amount, true).catch(console.error);
  220.  
  221.     const embed = new EmbedBuilder()
  222.         .setTitle('๐Ÿงน Purge Complete')
  223.         .setDescription(`${amount - 1} messages deleted.`)
  224.         .setColor(Colors.Blue);
  225.  
  226.     const logChannel = logChannels.purge ? message.guild.channels.cache.get(logChannels.purge) : null;
  227.     if (logChannel) await logChannel.send({ embeds: [embed] });
  228. }
  229.  
  230. client.login('YOUR_BOT_TOKEN');
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement