-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic.py
64 lines (50 loc) · 2.11 KB
/
music.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from dis import dis
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 in None:
await ctx.send("you aren't in voice")
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_channel.move_to(voice_channel)
@commands.command()
async def discconect(self, ctx):
await ctx.voice_client.dissconect()
@commands.command()
async def play(self, ctx, url):
ctx.voice_client_stop()
FFMPEG_OPTIONS = {'before_options' : '-reconnect 1 -reconnect_streanmed 1 -reconnect_delay_max 5',
'options' : '-vn'}
YDL_OPTIONS = {'format' : "bestaudio"}
vc = ctx.voice_channel
with youtube_dl.YouTubeDL(YDL_OPTIONS) as ydl:
info = ydl.exctract_info(url, download = False)
url2 = info['format'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
vc.play(source)
@commands.command()
async def pause(self, ctx):
await ctx.voice_client.pause()
await ctx.send("pause")
@commands.command()
async def resume(self, ctx):
await ctx.voice_client.resume()
await ctx.send("resume")
@commands.command(name='volume')
async def _volume(self, ctx: commands.Context, *, volume: int):
"""Sets the volume of the player."""
if not ctx.voice_state.is_playing:
return await ctx.send('Nothing being played at the moment.')
if 0 > volume > 100:
return await ctx.send('Volume must be between 0 and 100')
ctx.voice_state.volume = volume / 100
await ctx.send('Volume of the player set to {}%'.format(volume))
def setup(client):
client.add_cog(music(client))