(sock, message, args, context)
| 47 | groupOnly: true, |
| 48 | adminOnly: true, |
| 49 | async handler(sock, message, args, context) { |
| 50 | const chatId = context.chatId || message.key.remoteJid; |
| 51 | const isBotAdmin = context.isBotAdmin; |
| 52 | if (!isBotAdmin) { |
| 53 | await sock.sendMessage(chatId, { |
| 54 | text: '❌ *Please make the bot an admin first*' |
| 55 | }, { quoted: message }); |
| 56 | return; |
| 57 | } |
| 58 | let userToDemote = []; |
| 59 | const mentionedJids = message.message?.extendedTextMessage?.contextInfo?.mentionedJid; |
| 60 | if (mentionedJids && mentionedJids.length > 0) { |
| 61 | userToDemote = mentionedJids; |
| 62 | } |
| 63 | else if (message.message?.extendedTextMessage?.contextInfo?.participant) { |
| 64 | userToDemote = [message.message.extendedTextMessage.contextInfo.participant]; |
| 65 | } |
| 66 | if (userToDemote.length === 0) { |
| 67 | await sock.sendMessage(chatId, { |
| 68 | text: '❌ *Please mention a user or reply to their message*\n\nUsage: `.demote @user` or reply with `.demote`' |
| 69 | }, { quoted: message }); |
| 70 | return; |
| 71 | } |
| 72 | try { |
| 73 | await new Promise(resolve => setTimeout(resolve, 1000)); |
| 74 | await sock.groupParticipantsUpdate(chatId, userToDemote, "demote"); |
| 75 | const usernames = await Promise.all(userToDemote.map(async (jid) => { |
| 76 | return `@${jid.split('@')[0]}`; |
| 77 | })); |
| 78 | await new Promise(resolve => setTimeout(resolve, 1000)); |
| 79 | const demotionMessage = `*『 GROUP DEMOTION 』*\n\n` + |
| 80 | `👤 *Demoted User${userToDemote.length > 1 ? 's' : ''}:*\n` + |
| 81 | `${usernames.map(name => `• ${name}`).join('\n')}\n\n` + |
| 82 | `👑 *Demoted By:* @${message.key.participant ? message.key.participant.split('@')[0] : message.key.remoteJid.split('@')[0]}\n\n` + |
| 83 | `📅 *Date:* ${new Date().toLocaleString()}`; |
| 84 | await sock.sendMessage(chatId, { |
| 85 | text: demotionMessage, |
| 86 | mentions: [...userToDemote, message.key.participant || message.key.remoteJid] |
| 87 | }, { quoted: message }); |
| 88 | } |
| 89 | catch (error) { |
| 90 | console.error('Error in demote command:', error); |
| 91 | if (error.data === 429) { |
| 92 | await new Promise(resolve => setTimeout(resolve, 2000)); |
| 93 | try { |
| 94 | await sock.sendMessage(chatId, { |
| 95 | text: '❌ *Rate limit reached*\n\nPlease try again in a few seconds.' |
| 96 | }, { quoted: message }); |
| 97 | } |
| 98 | catch (retryError) { |
| 99 | console.error('Error sending retry message:', retryError); |
| 100 | } |
| 101 | } |
| 102 | else { |
| 103 | try { |
| 104 | await sock.sendMessage(chatId, { |
| 105 | text: '❌ *Failed to demote user(s)*\n\nMake sure the bot has sufficient permissions.' |
| 106 | }, { quoted: message }); |
nothing calls this directly
no outgoing calls
no test coverage detected