pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.08k stars 3.59k forks source link

Method addParticipants got error "Evaluation failed: TypeError: Cannot read properties of undefined (reading 'id')" #2590

Closed ronaldotantra closed 10 months ago

ronaldotantra commented 11 months ago

Is there an existing issue for this?

Describe the bug

got an error when trying to add member to a group

Expected behavior

not got an error and member successfully added to group

Steps to Reproduce the Bug or Issue

adding member and got this error


Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'id')
    at https://web.whatsapp.com/main.915cf42a1e688b3dec9a.js:5:897675
    at Array.some (<anonymous>)
    at https://web.whatsapp.com/main.915cf42a1e688b3dec9a.js:5:897658
    at Generator.next (<anonymous>)
    at t (https://web.whatsapp.com/vendor1~app.6470964955d882fdfd6f.js:2:66483)
    at s (https://web.whatsapp.com/vendor1~app.6470964955d882fdfd6f.js:2:66694)
    at https://web.whatsapp.com/vendor1~app.6470964955d882fdfd6f.js:2:66753
    at new Promise (<anonymous>)
    at https://web.whatsapp.com/vendor1~app.6470964955d882fdfd6f.js:2:66634
    at _ (https://web.whatsapp.com/main.915cf42a1e688b3dec9a.js:5:899325)
    at ExecutionContext._evaluateInternal (/Users/ronaldotantra/Desktop/rotan/botwa/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ExecutionContext.evaluate (/Users/ronaldotantra/Desktop/rotan/botwa/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async GroupChat.addParticipants (/Users/ronaldotantra/Desktop/rotan/botwa/node_modules/whatsapp-web.js/src/structures/GroupChat.js:62:16)
    at async Object.module.exports [as invite] (/Users/ronaldotantra/Desktop/rotan/botwa/func/invite.js:28:19)

### Relevant Code

_No response_

### Browser Type

Chromium

### WhatsApp Account Type

Standard

### Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

### Environment

OS: Mac, linux
WWebVersion 2.2344.53
node version v16.16.0

### Additional context

_No response_
ronaldotantra commented 11 months ago

could you help @alechkos ?

alechkos commented 11 months ago

@ronaldotantra provide the code you used

ronaldotantra commented 11 months ago

module.exports = async (client, msg) => {
    let content = msg.body.split(' ');
    let chats = await client.getChats();
    let data = content[1].split('\n');
    let groupid = data[0];
    data = data.slice(1, data.length);
    const group = chats.find((chat) => chat.id._serialized === groupid);

    let validNumber = [];
    for (let i = 0; i < data.length; i++) {
        if (data[i].startsWith('08')) {
            data[i] = data[i].replace('08', '628');
        }
        validNumber.push(data[i] + '@c.us');
    }
    try {
        let res = await group.addParticipants(validNumber, {isInviteV4Sent: true})
        console.log(res);
    } catch (error) {
        console.log(error);
    }
};
ronaldotantra commented 11 months ago

the message is like this


!invite 120xxx61@g.us
081xxxx2323
082xxx50536
08xxx9932
08xxxx68
0853xxxx86
088xxx071
alechkos commented 11 months ago

@ronaldotantra update the lib to 1.22.2-alpha.3 good luck

ronaldotantra commented 11 months ago

thankyouu it works but why it takes so long ?

        console.time("add");
        let res = await group.addParticipants(validNumber, {isInviteV4Sent: true})
        console.timeEnd("add");

add: 5:53.232 (m:ss.mmm)
alechkos commented 11 months ago

@ronaldotantra

thankyouu it works but why it takes so long ?

Because of the sleep property, you can change it as you want

Read the method description

ronaldotantra commented 10 months ago

ahh i see thankyouu