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.05k stars 3.58k forks source link

I can't send my musics to whatsapp .ogg #2127

Closed paulmai1967 closed 9 months ago

paulmai1967 commented 1 year ago

Is there an existing issue for this?

Describe the bug

I can´t send my audios in whatsapp-web.js, Can you jhelp me?

Expected behavior

When I try to to receive audios files .ogg typing "quero ouvir" (portuguese ("I want to listen") like a comand in the chat bot, the error bllow appears in the VS display.

Steps to Reproduce the Bug or Issue

WhatsApp succesfully connected! (node:23328) UnhandledPromiseRejectionWarning: ReferenceError: MessageMedia is not defined at Client. (C:\Users\WHATSAPP-ROBOT\Desktop\■CHATBOT-WHATSAPP\welcome_menu.js:140:20) at processTicksAndRejections (internal/process/task_queues.js:95:5) (Use node --trace-warnings ... to show where the warning was created) (node:23328) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:23328) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Relevant Code

if (msg.body !== null && msg.body === 'quero ouvir' || msg.body === 'quero ouvir ' || msg.body === 'Quero ouvir' || msg.body === 'Quero ouvir ' && msg.from.endsWith('@c.us')) { await delay(3000); //Delay de 3000 milisegundos mais conhecido como 3 segundos await client.sendMessage(msg.from, '😎 => Essas músicas são partes da minha Playlist. CRY FOR HELP de Rick Atsley de 1991 e TRUE de Spandau Ballet ... foram gravadas em Estúdio, espero que goste!'); const Media1 = MessageMedia.fromFilePath('/music/CRY FOR HELP - Rick Atsley.ogg'); client.sendMessage(msg.from, Media1, {sendAudioAsVoice: true}); const Media2 = MessageMedia.fromFilePath('/music/TRUE - Spandau Ballet.ogg'); client.sendMessage(msg.from, Media2, {sendAudioAsVoice: true}); }

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

No, I am not using Multi Device

Environment

Windows 10 Pro

Additional context

No response

amosayomide05 commented 1 year ago

Use node-lame to convert it to mp3

https://npmjs.com/package/node-lame

paulmai1967 commented 1 year ago

Use node-lame to convert it to mp3

https://npmjs.com/package/node-lame

Hi friend, thx for this. I have Movavi and can toconverto to mp3 any audio file, my question is: I´ve got in mp3 is it necessaty do install this node-lame?

Thxd

gkp1 commented 1 year ago

Bruh... Use await before MessageMedia.fromFilePath

paulmai1967 commented 1 year ago

Thx I will

Em sáb., 8 de abr. de 2023 09:54, gkp1 @.***> escreveu:

Bruh... Use await before MessageMedia.fromFilePath

— Reply to this email directly, view it on GitHub https://github.com/pedroslopez/whatsapp-web.js/issues/2127#issuecomment-1500886027, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7ATY6JARPOATBEDHXLEVPTXAFNZRANCNFSM6AAAAAAWV4VA2E . You are receiving this because you authored the thread.Message ID: @.***>