Zain-ul-din/whatsapp-ai-bot

TypeError: data.id.id.substring is not a function

ColAsTR opened this issue · 2 comments

I encountered an error while running the code that utilizes the this program.

The error message indicates a TypeError at line 91 of the Message.js file.

/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:91
this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';
^

TypeError: data.id.id.substring is not a function
at Message._patch (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:91:75)
at new Message (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:18:24)
at Client.sendMessage (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:699:16)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.9.0
error Command failed with exit code 1.

if you can just explain to me ways to solve this issue i will be gratefull.

thank you

The error message suggests that there is a TypeError in the Message.js file of the whatsapp-web.js module. Specifically, the error occurs on line 91 of the Message.js file.

The error message states that data.id.id.substring is not a function, which means that the substring method is being called on an object that doesn't have that method.

Possible Solutions from whatsapp-web.js issue.


Make this:

Open this file: \node_modules\whatsapp-web.js\src\structures\Message.js

  • Go to line 91 and change this:
this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';
  • for this:
this.deviceType = typeof data.id.id === 'string' && data.id.id.length > 21 ? 'android' : typeof data.id.id === 'string' && data.id.id.substring(0, 2) === '3A' ? 'ios' : 'web';

WhatsApp Web updated something that made that line stop working, but using this code it worked for me again.

image


Other possible Solutions

  • Update the whatsapp-web.js module: Update the whatsapp-web.js module to the latest version. You can do this by running the following command in your project directory:
    npm update whatsapp-web.js
    

thanks man