fix repeat cmd

This commit is contained in:
Milka64 2020-03-21 14:57:15 +01:00
parent d1af880652
commit fe649d530b

View file

@ -43,8 +43,7 @@ class Mybot(commands.Cog):
else:
folder = folder.lower()
audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3') if folder in str(f).lower()])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
self.sounds.append((source,ctx))
self.sounds.append((audio_file,ctx))
@commands.command()
async def repeat(self, ctx):
@ -78,12 +77,10 @@ class Mybot(commands.Cog):
print(user)
try:
audio_file = random.choice([f for f in os.listdir('/home/mika/kabot/kabot/kabot/Audio/%s/' % user) if f.endswith('.mp3')])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("/home/mika/kabot/kabot/kabot/Audio/%s/%s" % (user,audio_file)))
audio_file = '/home/mika/kabot/kabot/kabot/Audio/%s/' % user + audio_file
except:
audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3')])
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
self.sounds.append((source,ctx))
print(self.sounds)
self.sounds.append((audio_file,ctx))
@commands.command(help='Update local repo')
async def update(self, message):
@ -166,12 +163,13 @@ class Mybot(commands.Cog):
@tasks.loop(seconds=1.5)
async def play_next(self):
if self.sounds:
source,ctx = self.sounds[0]
audio_file,ctx = self.sounds[0]
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(audio_file))
if not ctx.voice_client.is_playing() and ctx.voice_client.is_connected():
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None)
self.sounds.pop(0)
self.sounds_history.reverse()
self.sounds_history.append((source,ctx))
self.sounds_history.append((audio_file,ctx))
self.sounds_history.reverse()
if len(self.sounds_history) >5:
self.sounds_history = self.sounds_history[:5]