Search YouTube with this prefix command: %search <term> . The bot will post the corresponding youtube link in an embed with a button.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let text = context.params.event.content.split(' ').slice(1).join(' ');
let result = `https://www.youtube.com/results?search_query=${text}`;
//embed part
if (context.params.event.content.startsWith(`%search`)) {
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
components: [
{
type: 1,
components: [
{
style: 5,
label: `YT`,
url: `https://www.youtube.com/results?search_query=${text}`,
disabled: false,
emoji: {
id: null,
name: `🎯`,
},
type: 2,
},
],
},
],
embeds: [
{
type: 'rich',
title: `YouTube`,
description: `Results for: ${text}`,
color: 0xff0000,
thumbnail: {
url: `https://acegif.com/wp-content/uploads/2021/4fh5wi/pepefrg-49.gif`,
height: 20,
width: 20,
},
},
],
});
}