twlite / youtube-sr

A dead-simple youtube metadata scraper
https://npmjs.com/package/youtube-sr
MIT License
113 stars 16 forks source link

Looking for help to use module #28

Closed DiyRex closed 3 years ago

DiyRex commented 3 years ago

Im sorry for asking this. I want to know how to get the result out from the promise insted of console.log(x).

code -

const YouTube = require("youtube-sr").default; YouTube.search("indila last dance", { limit: 3 }) .then(x => console.log(x)) .catch(console.error);

in here console.log(x) working fine. but I need to send the result as reply in my whatsapp bot. I couldnt find a away to do that.

twlite commented 3 years ago

you could do something like this

const YouTube = require("youtube-sr").default;

const results = await YouTube.search("indila last dance", { limit: 3 });

sendMessage(results.map((m, i) => `${i+1}. ${m.title}`).join("\n"));
/*
output:
1. title
2. title
3. title
...
*/
twlite commented 3 years ago

closing due to inactivity