Added play feature

This commit is contained in:
Louis Lacoste 2022-11-18 14:54:46 +01:00
parent 1cd1916feb
commit eb49b39abc

28
main.py
View file

@ -48,6 +48,7 @@ ytdl_format_options = {
}
ffmpeg_options = {
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'
}
@ -63,11 +64,11 @@ class YTDLSource(discord.PCMVolumeTransformer):
@classmethod
async def from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
if 'entries' in data:
# take first item from a playlist
data = data['entries'][0]
filename = data['title'] if stream else ytdl.prepare_filename(data)
filename = data['formats'][0]['url']#data['title'] if stream else ytdl.prepare_filename(data)
return filename
def random_playing_gif():
@ -117,6 +118,29 @@ async def play(ctx, url: str):
url="https://media.tenor.com/wQH1Lm24wLwAAAAM/de-la-merde-jean.gif")
await ctx.send(embed=embedPlaying)
@bot.command(name='play_song', help='To play song')
async def play(ctx,url):
try :
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
if is_a_youtube_url(url):
url = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(url, **ffmpeg_options))
embedPlaying = discord.Embed(
title="🤖PolaroBot joue", description=f"Je sais jouer de musique frère ! {url}")
embedPlaying.set_image(url=random_playing_gif())
ctx.send(embedPlaying)
else:
embedPlaying = discord.Embed(title="🤖PolaroBot veut casser ta gueule",
description=f"FREROT ?! C'EST QUOI {url} ? C'EST DE LA MERDE 💩💩💩 ! ")
embedPlaying.set_image(
url="https://media.tenor.com/wQH1Lm24wLwAAAAM/de-la-merde-jean.gif")
await ctx.send(embed=embedPlaying)
except Exception as err:
await ctx.send(f"The bot is not connected to a voice channel. Error : {err}")
@bot.command(name="join",help="Pour demander au bot de rejoindre le canal vocal")
async def join(ctx):