Closed TVARecordings closed 10 months ago
you can use const { participants } = chat
to get lists of user
Example to get is sender admin or not
const { participants, isGroup } = chat;
const isSenderAdmin = (isGroup) ? participants.find((participant) => participant.id. === sender.id).isAdmin : false;
the slution :
const contact = await message.getContact(); let num=contact.number; const chat = await message.getChat(); let IsAdmin=false; if(chat.isGroup){ for(let participant of chat.participants){ if(participant.id.user === num){ IsAdmin = participant.isAdmin; } }} console.log(IsAdmin) // if Admin will be true
Is there an existing issue for this?
Describe the bug
Visual Code Studio. NodeJS/Java etc all up-to-date.
Hello, i've got a open-source WA-Bot running, which sometimes (not everytime) returns "TypeError: Cannot read properties of undefined (reading 'isAdmin') at module.exports [as messageHandler] (D:\rzkytmgr Bot-SadBotBeforeAfterUpdate\handler\messageHandler.js:28:99)"
The line (28) is: "const isAdmin = groupMetadata ? groupMetadata.participants.find((res) => res.id === sender.id).isAdmin : undefined;"
This error only appears randomly after a 'command' has been issued, but does not error every time. In fact, it doesn't relate to a specific command either, nor a certain person or chat. It's out of the blue.
The error does not limit the running of the command, it runs anyway.
EDIT: It also appears when i start the bot with the command 'npm start'
Expected behavior
Expected: The error to not appear.
Steps to Reproduce the Bug or Issue
I really have no clue.
Relevant Code
module.exports = async (client, message) => { try { const msgAmount = await client.getAmountOfLoadedMessages(); if (msgAmount > 3000) await client.cutMsgCache();
Browser Type
Google Chrome
WhatsApp Account Type
WhatsApp Business
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
OS: W10, Visual Code Studio, NodeJS 20.0.0, Ubuntu latest version.
Additional context
No response