From 93653f33ec9b63f6c3c6468e276712b65877bfcb Mon Sep 17 00:00:00 2001 From: Clxud <71564480+cloudwithax@users.noreply.github.com> Date: Sun, 31 Oct 2021 13:22:01 -0400 Subject: [PATCH 1/3] forgot to await some funcs --- examples/basic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/basic.py b/examples/basic.py index 9bd4b46..14dad37 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -56,7 +56,7 @@ class Music(commands.Cog): player: pomice.Player = ctx.voice_client - player.destroy() + await player.destroy() await ctx.send("Player has left the channel.") @@ -96,7 +96,7 @@ class Music(commands.Cog): if player.is_paused: await ctx.send("Player is already paused!") - player.set_pause(pause=True) + await player.set_pause(pause=True) await ctx.send("Player has been paused") @@ -111,7 +111,7 @@ class Music(commands.Cog): if not player.is_paused: await ctx.send("Player is already playing!") - player.set_pause(pause=False) + await player.set_pause(pause=False) await ctx.send("Player has been resumed") @@ -126,10 +126,10 @@ class Music(commands.Cog): if not player.is_playing: await ctx.send("Player is already stopped!") - player.stop() + await player.stop() await ctx.send("Player has been stopped") bot = MyBot() -bot.run("token here") \ No newline at end of file +bot.run("token here") From 3e09556e114ea80819f9af9c5d399771a1115568 Mon Sep 17 00:00:00 2001 From: vveeps <54472340+vveeps@users.noreply.github.com> Date: Sun, 31 Oct 2021 19:57:43 +0200 Subject: [PATCH 2/3] return -> raise --- pomice/spotify/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pomice/spotify/client.py b/pomice/spotify/client.py index 0fceb84..ba517f5 100644 --- a/pomice/spotify/client.py +++ b/pomice/spotify/client.py @@ -58,7 +58,7 @@ class Client: spotify_id = result.group("id") if not result: - return InvalidSpotifyURL("The Spotify link provided is not valid.") + raise InvalidSpotifyURL("The Spotify link provided is not valid.") request_url = REQUEST_URL.format(type=spotify_type, id=spotify_id) @@ -90,4 +90,4 @@ class Client: tracks += [Track(track["track"]) for track in next_data["items"]] next_page_url = next_data["next"] - return Playlist(data, tracks) \ No newline at end of file + return Playlist(data, tracks) From 046f5413bb20d72dd10b7fbf5290d0d8bbc69f53 Mon Sep 17 00:00:00 2001 From: vveeps <54472340+vveeps@users.noreply.github.com> Date: Sun, 31 Oct 2021 20:09:14 +0200 Subject: [PATCH 3/3] make example a bit cleaner --- examples/basic.py | 104 ++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 55 deletions(-) diff --git a/examples/basic.py b/examples/basic.py index 14dad37..5eb33b3 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -1,84 +1,84 @@ -import pomice import discord - +import pomice from discord.ext import commands + class MyBot(commands.Bot): - def __init__(self) -> None: - super().__init__(command_prefix='!', activity=discord.Activity(type=discord.ActivityType.listening, name='to music!')) - + super().__init__( + command_prefix="!", + activity=discord.Activity(type=discord.ActivityType.listening, name="to music!") + ) + self.add_cog(Music(self)) - + self.loop.create_task(self.cogs["Music"].start_nodes()) + async def on_ready(self) -> None: print("I'm online!") - await self.cogs["Music"].start_nodes() class Music(commands.Cog): - - def __init__(self, bot) -> None: + def __init__(self, bot: commands.Bot) -> None: self.bot = bot - # In order to initialize a node, or really do anything in this library, you need to make a node pool + # In order to initialize a node, or really do anything in this library, + # you need to make a node pool self.pomice = pomice.NodePool() async def start_nodes(self): # You can pass in Spotify credentials to enable Spotify querying. # If you do not pass in valid Spotify credentials, Spotify querying will not work - - await self.pomice.create_node(bot=self.bot, host='127.0.0.1', port='3030', password='youshallnotpass', identifier='MAIN') + await self.pomice.create_node( + bot=self.bot, + host="127.0.0.1", + port="3030", + password="youshallnotpass", + identifier="MAIN" + ) print(f"Node is ready!") - - - - @commands.command(aliases=['connect']) - async def join(self, ctx: commands.Context, *, channel: discord.TextChannel = None) -> None: + @commands.command(aliases=["connect"]) + async def join(self, ctx: commands.Context, *, channel: discord.VoiceChannel = None) -> None: if not channel: - channel = getattr(ctx.author.voice, 'channel', None) + channel = getattr(ctx.author.voice, "channel", None) if not channel: - raise commands.CheckFailure('You must be in a voice channel to use this command' - 'without specifying the channel argument.') - - - # With the release of discord.py 1.7, you can now add a compatible VoiceProtocol class as a argument - # in channel.connect(). This library takes advantage of that and is how you initialize a player. + raise commands.CheckFailure( + "You must be in a voice channel to use this command " + "without specifying the channel argument." + ) + # With the release of discord.py 1.7, you can now add a compatible + # VoiceProtocol class as an argument in VoiceChannel.connect(). + # This library takes advantage of that and is how you initialize a player. await ctx.author.voice.channel.connect(cls=pomice.Player) - await ctx.send(f'Joined the voice channel `{channel}`') + await ctx.send(f"Joined the voice channel `{channel}`") - @commands.command(aliases=['dc', 'disconnect']) + @commands.command(aliases=["dc", "disconnect"]) async def leave(self, ctx: commands.Context): - if not ctx.voice_client: - raise commands.CommandError('No player detected') + raise commands.CommandError("No player detected") player: pomice.Player = ctx.voice_client await player.destroy() - await ctx.send("Player has left the channel.") - @commands.command(aliases=['p']) - async def play(self, ctx, *, search: str) -> None: - - # Checks if the players in the channel before we play anything + @commands.command(aliases=["p"]) + async def play(self, ctx: commands.Context, *, search: str) -> None: + # Checks if the player is in the channel before we play anything if not ctx.voice_client: await ctx.invoke(self.join) - player: pomice.Player = ctx.voice_client - # If you search a keyword, Pomice will automagically search the result using Youtube + # If you search a keyword, Pomice will automagically search the result using YouTube # You can pass in "search_type=" as an argument to change the search type # i.e: player.get_tracks("query", search_type=SearchType.ytmsearch) - # will search up any keyword results on Youtube Music - - results = player.get_tracks(f"{search}") + # will search up any keyword results on YouTube Music + results = await player.get_tracks(search) if not results: - raise commands.CommandError('No results were found for that search term.') + raise commands.CommandError("No results were found for that search term.") if isinstance(results, pomice.Playlist): await player.play(track=results.tracks[0]) @@ -86,50 +86,44 @@ class Music(commands.Cog): await player.play(track=results[0]) @commands.command() - async def pause(self, ctx): - + async def pause(self, ctx: commands.Context): if not ctx.voice_client: - raise commands.CommandError('No player detected') + raise commands.CommandError("No player detected") player: pomice.Player = ctx.voice_client if player.is_paused: - await ctx.send("Player is already paused!") + return await ctx.send("Player is already paused!") await player.set_pause(pause=True) - await ctx.send("Player has been paused") @commands.command() - async def resume(self, ctx): - + async def resume(self, ctx: commands.Context): if not ctx.voice_client: - raise commands.CommandError('No player detected') + raise commands.CommandError("No player detected") player: pomice.Player = ctx.voice_client if not player.is_paused: - await ctx.send("Player is already playing!") + return await ctx.send("Player is already playing!") await player.set_pause(pause=False) - await ctx.send("Player has been resumed") @commands.command() - async def stop(self, ctx): - + async def stop(self, ctx: commands.Context): if not ctx.voice_client: - raise commands.CommandError('No player detected') + raise commands.CommandError("No player detected") player: pomice.Player = ctx.voice_client if not player.is_playing: - await ctx.send("Player is already stopped!") + return await ctx.send("Player is already stopped!") await player.stop() - await ctx.send("Player has been stopped") bot = MyBot() -bot.run("token here") +bot.run("token")