diff --git a/Music-Bot.py b/Music-Bot.py index e25474a..69bc126 100644 --- a/Music-Bot.py +++ b/Music-Bot.py @@ -1,7 +1,7 @@ import asyncio import re from datetime import timedelta -from urllib.parse import quote_plus +from pytube import YouTube import aiohttp import yt_dlp @@ -110,9 +110,10 @@ else: async with aiohttp.ClientSession() as client: async with client.get("https://www.youtube.com/results", params=p, headers=h) as resp: dom = await resp.text() - found = re.findall(r"watch\?v=(\S{11})", dom)[0] - url = f"https://www.youtube.com/watch?v={found}" - return url + result = re.findall(r"watch\?v=(\S{11})", dom)[0:5] + print(result) + print("----") + return result intents = discord.Intents.default() @@ -242,7 +243,25 @@ else: @bot.slash_command(name="youtube", description="Searches YouTube for a given string and plays the first result") async def youtube(ctx, *, search: str): - url = await youtube_search(search=search) + results = await youtube_search(search=search) + embed = Embed(title=f"Search results for `{search}`", color=discord.Color.green()) + counter = 1 + for result in results: + url = f"https://youtube.com/watch?v={result}" + title = YouTube(url) + embed.add_field(name=f"{counter}", value=title.title, inline=False) + counter += 1 + print(url) + await ctx.respond(f"{success}**A short selection of videos will be displayed shortly...**") + msg = await ctx.send(embed=embed) + await msg.add_reaction(discord.PartialEmoji(name='one')) + await msg.add_reaction('') + await msg.add_reaction('three') + await msg.add_reaction('four') + await msg.add_reaction('five') + + + """ async with ctx.typing(): await ctx.respond("🤖 Your song is queued for download... please wait ", ephemeral=True) try: @@ -258,11 +277,12 @@ else: await asyncio.sleep(3) else: await ctx.voice_client.disconnect() + """ @play.before_invoke @stream.before_invoke - @youtube.before_invoke + #@youtube.before_invoke async def ensure_voice(ctx: commands.Context): if ctx.voice_client is None: if ctx.author.voice: @@ -274,7 +294,7 @@ else: - + """ @bot.event async def on_application_command_error(ctx, error): print(f"[on_application_command_error]\n{ctx.author}\n{error}") @@ -299,5 +319,6 @@ else: print(f"[on_command_error]\n{ctx.author}\n{error}") embed = Embed(title=f"{error}", color=15158332) await ctx.send(embed=embed) + """ bot.run(token=args.token, reconnect=True)