File size: 2,609 Bytes
8d8d92b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺
    ⭐PROJECT NAME:
    SUBZERO WHATSAPP MD BOT
    
    ⭐DEVELOPER
     MR FRANK 
     
    ⭐ MY TEAM
     XERO CODERS
     
    ⭐ OUR WEBSITE
     https://github.com/ZwSyntax/SUBZERO-MD

© TRY DECRYPTING IF YOU CAN⚠

╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺╺*/






const config = require('../config');
const { cmd, commands } = require('../command');

cmd({
    pattern: "kickall",
    desc: "Kicks all non-admin members from the group.",
    react: "🧨",
    category: "group",
    filename: __filename,
}, async (conn, mek, m, {
    from,
    quoted,
    isCmd,
    command,
    isGroup,
    sender,
    isAdmins,
    isOwner,
    groupMetadata,
    groupAdmins,
    isBotAdmins,
    reply
}) => {
    try {
        // Check if the command is used in a group
        if (!isGroup) return reply(`❌ This command is only for groups.`);

        // Check if the user is an admin
        if (!isAdmins) return reply(`❌ Only group admins can use this command.`);

        // Check if the user is the bot owner
        if (!isOwner) return reply(`❌ Only the bot owner can use this command.`);

        // Check if the bot has admin privileges
        if (!isBotAdmins) return reply(`❌ I need admin privileges to kick users.`);

        // Fetch all participants from the group
        const allParticipants = groupMetadata.participants;

        // Filter out admins and the bot itself
        const nonAdminParticipants = allParticipants.filter(member => 
            !groupAdmins.includes(member.id) && member.id !== conn.user.jid
        );

        if (nonAdminParticipants.length === 0) {
            return reply(`✅ There are no non-admin members to kick.`);
        }

        // Start removing non-admin participants
        for (let participant of nonAdminParticipants) {
            await conn.groupParticipantsUpdate(from, [participant.id], "remove")
                .catch(err => console.error(`Failed to remove ${participant.id}:`, err));
        }

        // Send a confirmation message once done
        reply(`✅ Successfully kicked all non-admin members from the group.`);
    } catch (e) {
        console.error('Error kicking users:', e);
        reply('❌ An error occurred while trying to kick all members. Please try again.');
    }
});