twitch_bot/commands/yts.js
2023-02-06 16:02:34 +02:00

36 lines
970 B
JavaScript

const command = {
name: "yts",
desc: "search youtube for a video",
restricted: false,
mod: false,
run: async (client, msg, splitted) => {
if (splitted[2] === undefined) {
await client
.say(msg.channelName, `${msg.displayName}, supply a search PoroSad`)
.catch((err) => console.log(err));
return;
}
const data = await fetch(
`https://invidious.epicsite.xyz/api/v1/search?type=video&q=${encodeURIComponent(
splitted.slice(2).join(" ")
)}`
)
.then((res) => res.json())
.then((data) => data[0])
.catch((err) => console.log(err));
await client
.say(
msg.channelName,
`${msg.displayName}, YouTube video with search term: ${splitted
.slice(2)
.join(" ")}; ${data.title} by ${
data.author
}, Link: youtu.be/watch?v=${data.videoId}`
)
.catch((err) => console.log(err));
},
};
module.exports = { command };