From 7ea3f3490b15563cc9d02eb7c6d97ca163830997 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 6 Sep 2021 21:44:33 +0530 Subject: [PATCH 1/5] Remove trailing spaces and blank lines --- main.py | 5 ++--- yamb/cogs/music.py | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 40035b2..ddbcd26 100644 --- a/main.py +++ b/main.py @@ -21,18 +21,17 @@ def main(): handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w') handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) logger.addHandler(handler) - + # Bot Setup bot = commands.Bot(command_prefix=when_mentioned_or('?'), description=description) @bot.event async def on_ready(): print(f'Logged in as {bot.user.name}#{bot.user.discriminator}') - + token = os.environ.get('BOT_TOKEN') bot.add_cog(Music(bot)) bot.run(token) if __name__ == '__main__': main() - diff --git a/yamb/cogs/music.py b/yamb/cogs/music.py index e4257bf..f0adfe0 100644 --- a/yamb/cogs/music.py +++ b/yamb/cogs/music.py @@ -93,6 +93,3 @@ async def ensure_voice(self, ctx): raise commands.CommandError("Author not connected to a voice channel.") elif ctx.voice_client.is_playing(): ctx.voice_client.stop() - - - From a5de62b1565cf42993372baf5f18661630b89ce4 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 6 Sep 2021 22:02:12 +0530 Subject: [PATCH 2/5] Add now playing command --- yamb/cogs/music.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/yamb/cogs/music.py b/yamb/cogs/music.py index f0adfe0..685ed18 100644 --- a/yamb/cogs/music.py +++ b/yamb/cogs/music.py @@ -67,6 +67,17 @@ async def play(self, ctx, *args): await ctx.send('Now playing: {}'.format(player.title)) + @commands.command() + async def np(self, ctx): + """Display the currently playing track""" + + if ctx.voice_client is None: + return await ctx.send("Not connected to a voice channel.") + + title = ctx.voice_client.source.title + + await ctx.send(f'Now playing: {title}') + @commands.command() async def volume(self, ctx, volume: int): """Changes the player's volume""" From 53f8adef06dd84928548fea6caded134554ac8a8 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 6 Sep 2021 22:23:30 +0530 Subject: [PATCH 3/5] Add aliases for some commands --- yamb/cogs/music.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yamb/cogs/music.py b/yamb/cogs/music.py index 685ed18..cfe5f65 100644 --- a/yamb/cogs/music.py +++ b/yamb/cogs/music.py @@ -56,7 +56,7 @@ class Music(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.command(aliases=['p']) async def play(self, ctx, *args): """Plays music from query""" @@ -78,7 +78,7 @@ async def np(self, ctx): await ctx.send(f'Now playing: {title}') - @commands.command() + @commands.command(aliases=['vol']) async def volume(self, ctx, volume: int): """Changes the player's volume""" @@ -88,7 +88,7 @@ async def volume(self, ctx, volume: int): ctx.voice_client.source.volume = volume / 100 await ctx.send("Changed volume to {}%".format(volume)) - @commands.command() + @commands.command(aliases=['dc']) async def stop(self, ctx): """Stops and disconnects the bot from voice""" From ba21468fef38c80266706e1f6747c393e158f866 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 6 Sep 2021 22:23:55 +0530 Subject: [PATCH 4/5] Improve now playing with embed and requester Also switch `play` to call `np` after starting the player, instead of sending its own now playing message. --- yamb/cogs/music.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/yamb/cogs/music.py b/yamb/cogs/music.py index cfe5f65..6a711cd 100644 --- a/yamb/cogs/music.py +++ b/yamb/cogs/music.py @@ -63,9 +63,10 @@ async def play(self, ctx, *args): url = ' '.join(args) async with ctx.typing(): player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) + player.requester = ctx.author ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None) - await ctx.send('Now playing: {}'.format(player.title)) + await self.np(ctx) @commands.command() async def np(self, ctx): @@ -75,8 +76,16 @@ async def np(self, ctx): return await ctx.send("Not connected to a voice channel.") title = ctx.voice_client.source.title + url = ctx.voice_client.source.url + requester = ctx.voice_client.source.requester - await ctx.send(f'Now playing: {title}') + embed = discord.Embed() + embed.add_field(name="Now playing", + value=f'[{title}]({url})') + embed.add_field(name="Requested by", + value=requester.mention) + + await ctx.send(embed=embed) @commands.command(aliases=['vol']) async def volume(self, ctx, volume: int): From 8fe7cd7c3520eb26828867571770f42ba5954168 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Mon, 6 Sep 2021 22:40:57 +0530 Subject: [PATCH 5/5] Add pause and resume commands --- yamb/cogs/music.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/yamb/cogs/music.py b/yamb/cogs/music.py index 6a711cd..23edae3 100644 --- a/yamb/cogs/music.py +++ b/yamb/cogs/music.py @@ -87,6 +87,17 @@ async def np(self, ctx): await ctx.send(embed=embed) + @commands.command() + async def pause(self, ctx): + """Pauses the player""" + ctx.voice_client.pause() + + @commands.command() + async def resume(self, ctx): + """Resumes the player""" + ctx.voice_client.resume() + + @commands.command(aliases=['vol']) async def volume(self, ctx, volume: int): """Changes the player's volume"""