Skip to content

Commit

Permalink
Added skip command
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluxticks committed Jul 27, 2021
1 parent 7e7762f commit cffd781
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/esportsbot/cogs/MusicCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,33 @@ async def leave_channel_command(self, context: commands.Context, force: str = ""
await self.remove_active_guild(context.guild)
await self.update_messages(context.guild.id)

@command_group.command(
name="skip",
usage="[songs to skip]",
help="Skips the current song. If a number is given it will also skip n-1 songs after the current song."
"For example, if 'songs to skip' is 4, the next song to play would be song 4 in the queue."
)
async def skip_song(self, context: commands.Context, skip_count=0):
try:
skip_count = int(skip_count) - 1
except ValueError:
skip_count = 0

if context.author in self.active_guilds.get(context.guild.id).get("voice_channel").members:
await self.__skip_song(context.guild.id, skip_count)

async def __skip_song(self, guild_id, skip_count):
if guild_id not in self.active_guilds:
return

await self.active_guilds.get(guild_id).get("voice_client").stop()
self.active_guilds.get(guild_id)["current_song"] = None
if skip_count > len(self.active_guilds.get(guild_id).get("queue")):
await self.play_queue(guild_id)
else:
self.active_guilds.get(guild_id)["queue"] = self.active_guilds.get(guild_id)["queue"][skip_count:]
await self.play_queue(guild_id)

@staticmethod
async def clear_music_channel(channel):
await channel.purge(limit=int(sys.maxsize))
Expand Down

0 comments on commit cffd781

Please sign in to comment.