Как мне ставить на паузу видео в очереди Discord.py

Есть музыкальный бот, который проигрывает музыку в очереди, и у меня есть функция которая должна ставить видео на паузу, но вместо этого она его скипает. Как мне это наладить?

Вот код:

list_of_song = []

async def play(ctx, *, url):
    global voice
    if not ctx.message.author.voice:
        await ctx.send('**Ви зараз не находитесь в голосовому каналі!**')
        return
    else:
        channel = ctx.message.author.voice.channel

    try:
        voice = await channel.connect()
    except:
        pass
    list_of_song.append(url)
    try:
        while True:
            with YoutubeDL(YDL_OPT) as ydl:
                info = ydl.extract_info(list_of_songs[0], download=False)
            
            URL = info['url']
            voice.play(FFmpegPCMAudio(
              executable='Путь\\к\\файлу\\ffmpeg.exe',
                source=URL,
                **FFMPEG_OPT))
            
            while voice.is_playing():
                await asyncio.sleep(1)
            if not voice.is_playing():
                if voice.pause():
                    pass
                else:
                    list_of_songs.pop(0)
    except:
        pass
async def stop(ctx):
    server = ctx.message.guild
    voice_channel = server.voice_client
    if not ctx.message.author.voice:
        await ctx.send('**Ви зараз не находитесь в голосовому каналі!**')
        return
    else:
        if not voice_channel.is_playing():
            await ctx.send('**На данний момент відео вже поставлене на паузу!**')
        else:
            voice_channel.pause()
            await ctx.send(f'**Відео поставлено на паузу користувачем `{ctx.author}`**:pause_button:')
        ```

Ответы (1 шт):

Автор решения: denisnumb

Просто двойное условие в while, то есть ждем, пока музыка играет или на паузе:

while voice.is_playing() or voice.is_paused():
    await asyncio.sleep(1)

И в итоге ваш код можно записать компактнее в таком виде:

 list_of_song.append(url)

while len(list_of_songs) > 0:
    with YoutubeDL(YDL_OPT) as ydl:
        info = ydl.extract_info(list_of_songs[0], download=False)
    
    URL = info['url']
    voice.play(FFmpegPCMAudio(executable='Путь\\к\\файлу\\ffmpeg.exe', source=URL, **FFMPEG_OPT))
    
    while voice.is_playing() or voice.is_paused():
        await asyncio.sleep(1)
    list_of_songs.pop(0)
→ Ссылка