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.53k stars 3.7k forks source link

fix: `delete` function for messages #3301

Open alechkos opened 1 month ago

alechkos commented 1 month ago

PR Details

Fix for the Message.delete function.

Description

The PR fixes an issue where the delete function does not delete messages.

Also was added a possibility to pass a second boolean value into the function for clearing media in the device (true by default).

Related Issue

closes #3245

How Has This Been Tested

// client initialization...

client.on('message', async (message) => {
    const sender = 'XXXXXXXXXXX@c.us';
    if (message?.author === sender || message?.from === sender) {
        // delete for everyone: true, clear media in device: true (by default)
        await message.delete(true);
        // delete for everyone: true, clear media in device: false
        await message.delete(true, false);
        // delete for everyone: false, clear media in device: true (by default)
        await message.delete(false);
        // delete for everyone: false, clear media in device: false
        await message.delete(false, false);
    }
});

Everything works as expected.

You can try the fix by running one of the following commands:

Types of changes

Checklist