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.21k stars 3.63k forks source link

Showing chat.fetchMessages is not a function . #2347

Closed dardarsh closed 10 months ago

dardarsh commented 1 year ago

Is there an existing issue for this?

Describe the bug

I want to fetch last 2 messages of a particular chat . I have the below code

client.getChats()
.then((chat)=>{
    console.log(chat.fetchMessages({limit: 2})).then((e)=>{console.log(e)})
})

upon running this code i am getting the following error

(node:35964) UnhandledPromiseRejectionWarning: TypeError: chat.fetchMessages is not a function
    at evalmachine.<anonymous>:3:22

Expected behavior

I want last 2 messages of that chat to appear

Steps to Reproduce the Bug or Issue

  1. connect to the client
  2. run the above code given

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

Windows Android latest version whatsapp web js

Additional context

No response

opssemnik commented 1 year ago

client.getChats() returns an array of chats, not just a single object You need to forEach first to get the object of each chat