#Can not extend Client class

2 messages · Page 1 of 1 (latest)

modern cloud
#

I'm having problems to initialize whatsapp-web.js inside a class. Had anyone done this before?

I wrote on one file


class Whatsapp extends Client{
    constructor() {
        super();
        this.startBot()
    }

    startBot(){
        this.on('send', async (number, message) => {
            this.client.sendMessage(number, message);
        });
    }
}

module.exports = Whatsapp; // Exporting the extended class```

and then I call

const Whatsapp=require('whatsapp');
const LocalAuth = require('whatsapp-web.js');

const whatsapp = new Whatsapp({
authStrategy: new LocalAuth(),
});

and I get the error :

class Whatsapp extends Client{
                       ^
TypeError: Class extends value #<Object> is not a constructor or null
wheat rampart
#

const client = require('whatsapp-web.js');
should be

const { Client as client } = require('whatsapp-web.js');