Skip to content

Commit 340050f

Browse files
committed
Update music.py
1 parent b16de19 commit 340050f

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/cogs/music.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def __init__(self, bot):
9898
# "queued": 0,
9999
# "vol": 1,
100100
# "loop_queue": False,
101-
# "repeat_song": False
101+
# "repeat_song": False,
102+
# "inside_keep_playing": False
102103
# }
103104
# -------------------------------------
104105
self.music_queue = {}
@@ -120,7 +121,8 @@ def add_guild(self, ctx):
120121
"queued": 0,
121122
"vol": 1,
122123
"loop_queue": False,
123-
"repeat_song": False
124+
"repeat_song": False,
125+
"inside_keep_playing": False
124126
}
125127
if str(ctx.guild.id) not in self.music_queue.keys():
126128
self.music_queue[str(ctx.guild.id)] = []
@@ -174,6 +176,8 @@ async def leave_command(self, ctx):
174176
self.properties[str(ctx.guild.id)]["loop_queue"] = False
175177
self.properties[str(ctx.guild.id)]["repeat_song"] = False
176178
self.properties[str(ctx.guild.id)]["currently_playing_player"] = None
179+
self.properties[str(ctx.guild.id)]["is_playing"] = False
180+
self.properties[str(ctx.guild.id)]["inside_keep_playing"] = False
177181
if ctx.voice_client is None:
178182
embed = self.embed_error_no_vc_dex
179183
await ctx.send(embed=embed)
@@ -227,6 +231,7 @@ async def play_music_from_player(self, ctx, *, player):
227231
# ----------------------------------------------------------------------------------------------------------------------
228232

229233
async def keep_playing(self, ctx):
234+
self.properties[str(ctx.guild.id)]["inside_keep_playing"] = True
230235
while ((len(self.music_queue[str(ctx.guild.id)]) - self.properties[str(ctx.guild.id)]["current"] > 1) or (self.properties[str(ctx.guild.id)]["loop_queue"] is True)) and (len(self.music_queue[str(ctx.guild.id)]) > 0):
231236
if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())):
232237
self.properties[str(ctx.guild.id)]["is_playing"] = True
@@ -239,6 +244,7 @@ async def keep_playing(self, ctx):
239244
ctx.guild.id)]["current"]][0] = player
240245
await self.play_music_from_player(self.music_queue[str(ctx.guild.id)][self.properties[str(ctx.guild.id)]["current"]][1], player=player)
241246
await asyncio.sleep(0.5)
247+
self.properties[str(ctx.guild.id)]["inside_keep_playing"] = False
242248
return
243249
# ----------------------------------------------------------------------------------------------------------------------
244250

@@ -256,7 +262,8 @@ async def play_command(self, ctx, *, url: typing.Optional[str]):
256262
ctx.voice_client.resume()
257263
elif len(self.music_queue[str(ctx.guild.id)]) > 0:
258264
if not ctx.voice_client.is_playing():
259-
await self.keep_playing(ctx)
265+
if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]:
266+
await self.keep_playing(ctx)
260267
else:
261268
embed = discord.Embed(
262269
title="Error",
@@ -310,7 +317,8 @@ async def play_command(self, ctx, *, url: typing.Optional[str]):
310317
embed.add_field(name="Queue Position", value=len(
311318
self.music_queue[str(ctx.guild.id)]), inline=True)
312319
await ctx.send(embed=embed)
313-
await self.keep_playing(ctx)
320+
if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]:
321+
await self.keep_playing(ctx)
314322
return
315323
# ----------------------------------------------------------------------------------------------------------------------
316324

@@ -389,7 +397,8 @@ async def dplay_command(self, ctx, *, url):
389397
embed.add_field(name="Queue Position", value=len(
390398
self.music_queue[str(ctx.guild.id)]), inline=True)
391399
await ctx.send(embed=embed)
392-
await self.keep_playing(ctx)
400+
if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]:
401+
await self.keep_playing(ctx)
393402
return
394403
# ----------------------------------------------------------------------------------------------------------------------
395404

@@ -781,8 +790,8 @@ async def resume_command(self, ctx):
781790
await ctx.send(embed=embed)
782791
elif ctx.voice_client.is_paused():
783792
ctx.voice_client.resume()
784-
elif len(self.music_queue[str(ctx.guild.id)]) > 0:
785-
if not ctx.voice_client.is_playing():
793+
elif not ctx.voice_client.is_playing():
794+
if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]:
786795
await self.keep_playing(ctx)
787796
return
788797
# ----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)