I want to use key-words in searching song instead of url in youtube-dl. e.x .play take my horse But I found examples when the song is being downloaded to PC, I don't wanna do it, just do the same like now but search with key-words. I'm new in discord.py and youtube-dl for me it dark forest. Help me pls !
music.py - there is a my code now, with url search.
import discord
from discord.ext import commands
import youtube_dl
class Music(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def join(self, ctx):
if ctx.author.voice is None:
await ctx.send("Вы не находитесь в голосовом канале !")
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_client.move_to(voice_channel)
@commands.command()
async def disconnect(self, ctx):
await ctx.voice_client.disconnect()
@commands.command()
async def play(self, ctx, url):
try:
if ctx.author.voice is None:
await ctx.send("Вы не находитесь в голосовом канале !")
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_client.move_to(voice_channel)
ctx.voice_client.stop()
ffmpeg_options = {
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'
}
ydl_options = {
'format': 'bestaudio'
}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(ydl_options) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2, **ffmpeg_options)
vc.play(source)
except discord.ClientException:
await ctx.send("Already Playing Song")
@commands.command()
async def pause(self, ctx):
ctx.voice_client.pause()
embed = discord.Embed(
title="",
description="***Приостановлено.***",
color=0x2f3136
)
await ctx.send(embed=embed)
@commands.command()
async def resume(self, ctx):
ctx.voice_client.resume()
embed = discord.Embed(
title="",
description="***Возобновлено.***",
color=0x2f3136
)
await ctx.send(embed=embed)
def setup(client):
client.add_cog(Music(client))