0

I'm working on an discord music bot with python, I already have a function that plays the songs that are in a queue but I would like to add a command that plays the queue in an infinite loop. How can I do this?

Those are the commands that set the loop value to True or False

@client.command(name='loop', help='Enable loop')
async def loop_on(ctx):
    global loop
    loop = True
    await ctx.send('Looping')

@client.command(name='dunloop', help='Disable loop')
async def loop_off(ctx):
    global loop
    loop = False
    await ctx.send('Loop disabled')

And here the code that plays the music

@client.command(name='play', help='Plays Music')
async def play(ctx):
    global queue

    if not ctx.message.author.voice:
        await ctx.send("You are not connected to a voice channel")
        return
    
    else:
        channel = ctx.message.author.voice.channel

    try: await channel.connect()
    except: pass

    server = ctx.message.guild
    voice_channel = server.voice_client
    
    try:
        async with ctx.typing():
            player = await YTDLSource.from_url(queue[0], loop=client.loop)
            voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
            
            if loop:
                queue.append(queue[0])

            del(queue[0])
            
        await ctx.send('**Playing :** {}'.format(player.title))
        

    except:
        await ctx.send('The queue is empty .Use ?queue to add a song !')

And now I would like to add a command that plays the queue without stopping while the loop value is set to True.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.