-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.py
76 lines (63 loc) · 2.33 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
65
66
67
68
69
70
71
72
73
74
75
76
######### MUSIC PLAYER, IN PROGRESS #########
import discord
from discord.ext import commands
import youtube_dl
import json
players = {}
queues = {}
class music:
def __init__(self, client):
self.client = client
def check_queue(self, id):
if queues[id] != []:
player = queues[id].pop(0)
players[id] = player
player.start()
@commands.command(pass_context=True)
async def join(self, ctx):
channel = ctx.message.author.voice.voice_channel
await self.client.join_voice_channel(channel)
#needs to fix bug where if called when user is not in a voice channel, the bot will go to the hospital
@commands.command(pass_context=True)
async def leave(self, ctx):
server = ctx.message.server
voice_client = self.client.voice_client_in(server) #if no voice channel exists in the server, this will make the bot crash
await voice_client.disconnect()
#still needs some work done
@commands.command(pass_context=True)
async def play(self, ctx, url):
server = ctx.message.server
voice_client = self.client.voice_client_in(server)
player = await voice_client.create_ytdl_player(url, after=lambda: self.check_queue(server.id))
players[server.id] = player
player.start()
@commands.command(pass_context=True)
async def pause(self, ctx):
server_id = ctx.message.server.id
players[server_id].pause()
@commands.command(pass_context=True)
async def stop(self, ctx):
server_id = ctx.message.server.id
players[server_id].stop()
@commands.command(pass_context=True)
async def resume(self, ctx):
server_id = ctx.message.server.id
players[server_id].resume()
@commands.command(pass_context=True)
async def skip(self, ctx):
server_id = ctx.message.server.id
players[server_id].stop()
#if you are reading this, u r a nerd.
@commands.command(pass_context=True)
async def queue(self, ctx, url):
server = ctx.message.server
voice_client = self.client.voice_client_in(server)
#it assumes bot is already in a voice channel, if not, boom it goes ripperino
player = await voice_client.create_ytdl_player(url, after=lambda: self.check_queue(server.id))
if server.id in queues:
queues[server.id].append(player)
else:
queues[server.id] = [player]
await self.client.say("Gottit, I added the song!")
def setup(client):
client.add_cog(music(client))