@@ -10,63 +10,71 @@ import re
1010
1111from discord.ext import commands
1212
13- URL_REG = re.compile(r ' https? ://(?: www\. ) ? . + ' )
13+ URL_REG = re.compile(r " https? ://(?: www\. ) ? . + " )
1414
15- class MyBot (commands .Bot ):
1615
17- def __init__ (self ) -> None :
18- super ().__init__ (command_prefix = ' !' , activity = discord.Activity(type = discord.ActivityType.listening, name = ' to music!' ))
16+ class MyBot (commands .Bot ):
17+ def __init__ (self ) -> None :
18+ super ().__init__ (
19+ command_prefix = " !" ,
20+ activity = discord.Activity(
21+ type = discord.ActivityType.listening, name = " to music!"
22+ ),
23+ )
1924
20- self .add_cog(Music(self ))
25+ self .add_cog(Music(self ))
2126
22- async def on_ready (self ) -> None :
23- print (" I'm online!" )
24- await self .cogs[" Music" ].start_nodes()
27+ async def on_ready (self ) -> None :
28+ print (" I'm online!" )
29+ await self .cogs[" Music" ].start_nodes()
2530
2631
2732class Music (commands .Cog ):
28-
29- def __init__ (self , bot ) -> None :
30- self .bot = bot
31-
32- self .pomice = pomice.NodePool()
33-
34- async def start_nodes (self ):
35- await self .pomice.create_node(bot = self .bot, host = ' 127.0.0.1' , port = ' 3030' ,
36- password = ' youshallnotpass' , identifier = ' MAIN' )
37- print (f " Node is ready! " )
38-
39-
40-
41- @commands.command (name = ' join' , aliases = [' connect' ])
42- async def join (self , ctx : commands.Context, * , channel : discord.TextChannel = None ) -> None :
43-
44- if not channel:
45- channel = getattr (ctx.author.voice, ' channel' , None )
33+ def __init__ (self , bot ) -> None :
34+ self .bot = bot
35+
36+ self .pomice = pomice.NodePool()
37+
38+ async def start_nodes (self ):
39+ await self .pomice.create_node(
40+ bot = self .bot,
41+ host = " 127.0.0.1" ,
42+ port = " 3030" ,
43+ password = " youshallnotpass" ,
44+ identifier = " MAIN" ,
45+ )
46+ print (f " Node is ready! " )
47+
48+ @commands.command (name = " join" , aliases = [" connect" ])
49+ async def join (
50+ self , ctx : commands.Context, * , channel : discord.TextChannel = None
51+ ) -> None :
52+ if not channel:
53+ channel = getattr (ctx.author.voice, " channel" , None )
4654 if not channel:
47- raise commands.CheckFailure(' You must be in a voice channel to use this command'
48- ' without specifying the channel argument.' )
49-
50-
51- await ctx.author.voice.channel.connect(cls = pomice.Player)
52- await ctx.send(f ' Joined the voice channel ` { channel} ` ' )
55+ raise commands.CheckFailure(
56+ " You must be in a voice channel to use this command"
57+ " without specifying the channel argument."
58+ )
5359
54- @commands.command ( name = ' play ' )
55- async def play ( self , ctx , * , search : str ) -> None :
60+ await ctx.author.voice.channel.connect( cls = pomice.Player )
61+ await ctx.send( f " Joined the voice channel ` { channel } ` " )
5662
57- if not ctx.voice_client:
63+ @commands.command (name = " play" )
64+ async def play (self , ctx , * , search : str ) -> None :
65+ if not ctx.voice_client:
5866 await ctx.invoke(self .join)
5967
60- player = ctx.voice_client
68+ player = ctx.voice_client
6169
62- results = await player.get_tracks(query = f ' { search} ' )
70+ results = await player.get_tracks(query = f " { search} " )
6371
64- if not results:
65- raise commands.CommandError(' No results were found for that search term.' )
72+ if not results:
73+ raise commands.CommandError(" No results were found for that search term." )
6674
67- if isinstance (results, pomice.Playlist):
75+ if isinstance (results, pomice.Playlist):
6876 await player.play(track = results.tracks[0 ])
69- else :
77+ else :
7078 await player.play(track = results[0 ])
7179
7280
0 commit comments