Added play feature
This commit is contained in:
parent
1cd1916feb
commit
eb49b39abc
1 changed files with 37 additions and 13 deletions
50
main.py
50
main.py
|
|
@ -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():
|
||||
|
|
@ -104,18 +105,41 @@ async def restart(ctx):
|
|||
|
||||
@bot.command(aliases=['play_music'], pass_context=True)
|
||||
async def play(ctx, url: str):
|
||||
"""Playing a song"""
|
||||
if is_a_youtube_url(url):
|
||||
embedPlaying = discord.Embed(
|
||||
title="🤖PolaroBot joue", description=f"Je sais pas encore jouer de musique mais tkt frère, vla ton URL mon reuf : {url}")
|
||||
embedPlaying.set_image(url=random_playing_gif())
|
||||
"""Playing a song"""
|
||||
if is_a_youtube_url(url):
|
||||
embedPlaying = discord.Embed(
|
||||
title="🤖PolaroBot joue", description=f"Je sais pas encore jouer de musique mais tkt frère, vla ton URL mon reuf : {url}")
|
||||
embedPlaying.set_image(url=random_playing_gif())
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
@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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue