diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/music/skip.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/cogs/music/skip.py b/cogs/music/skip.py new file mode 100644 index 0000000..f48218b --- /dev/null +++ b/cogs/music/skip.py | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | from discord.ext import commands | ||
| 2 | import discord | ||
| 3 | |||
| 4 | class Skip(commands.Cog): | ||
| 5 | def __init__(self, bot): | ||
| 6 | self.bot = bot | ||
| 7 | self.queues = {} | ||
| 8 | |||
| 9 | def get_queue(self, guild_id): | ||
| 10 | return self.queues.setdefault(guild_id, []) | ||
| 11 | |||
| 12 | def play_next(self, ctx, vc, guild_id): | ||
| 13 | queue = self.get_queue(guild_id) | ||
| 14 | if queue: | ||
| 15 | _, _, file_path = queue[0] | ||
| 16 | def after_playing(error=None): | ||
| 17 | if queue: | ||
| 18 | queue.pop(0) | ||
| 19 | if queue: | ||
| 20 | _, _, next_file = queue[0] | ||
| 21 | if not vc.is_playing(): | ||
| 22 | vc.play(discord.FFmpegPCMAudio(next_file), after=after_playing) | ||
| 23 | if not vc.is_playing(): | ||
| 24 | vc.play(discord.FFmpegPCMAudio(file_path), after=after_playing) | ||
| 25 | |||
| 26 | @commands.slash_command(name="pomiĆ", description="przeskocz do nastepnej melodyji") | ||
| 27 | async def pomin(self, ctx): | ||
| 28 | guild_id = ctx.guild.id | ||
| 29 | vc = ctx.voice_client | ||
| 30 | if vc and vc.is_playing(): | ||
| 31 | queue = self.get_queue(guild_id) | ||
| 32 | if queue: | ||
| 33 | queue.pop(0) | ||
| 34 | if queue: | ||
| 35 | vc.stop() | ||
| 36 | self.play_next(ctx, vc, guild_id) | ||
| 37 | await ctx.respond("przeskoczono do nastepnej melodyji") | ||
| 38 | else: | ||
| 39 | await ctx.respond("koleyjka jest pustawa") | ||
| 40 | await vc.disconnect() | ||
| 41 | else: | ||
| 42 | await ctx.respond("nic nie gra") | ||
| 43 | else: | ||
| 44 | await ctx.respond("nic nie gra") | ||
| 45 | |||
| 46 | def setup(bot): | ||
| 47 | bot.add_cog(Skip(bot)) \ No newline at end of file | ||
