TypeError: __init__() got an unexpected keyword argument 'after'

2.6k views Asked by At

I am trying to loop the function repeatedly with this code which gives me the error as the question.

async def looptrack(ctx, *times):
    global timess
    voice = get(bot.voice_clients, guild=ctx.guild)
    if (ctx.author.voice):
        if voice and voice.is_playing():
            if os.path.exists(audio):
                if times:
                    times = int(''.join(map(str, times)))
                    timess = str(times)
                    if (timess == "0"):
                        global looptrack_infinite
                        looptrack_infinite = await ctx.send("Will loop "+vTT+" infinite times")                                
                        await tracklooper(0)    
                    else:
                        global looptrack_set_times
                        looptrack_set_times = await ctx.send("Will loop "+vTT+" for "+timess+" times")
                        voice.play(discord.FFmpegPCMAudio(audio, after=lambda e: looptrack(ctx)))
                else:
                    global looptrack_fail
                    looptrack_fail = await ctx.send("Please enter the number of times to repeat, 0 for infinite times") 
                    await looptrack_fail.delete(delay=10)
            else:
                global looptrack_no_audio
                looptrack_no_audio = await ctx.send("Audio file not found")
                await looptrack_no_audio.delete(delay=10)
        else:
            global looptrack_notin_channel
            looptrack_notin_channel = await ctx.send("No song loaded")
            await looptrack_notin_channel.delete(delay=10)
    else:
        looptrack_client_notcn = await ctx.send("You are not connected to any voice channel")
        await looptrack_client_notcn.delete(delay=10)

This is a part of the code in my discord bot where i am trying to play a music in the voice channel repeatedly if the command looptrack is called

Edit: as suggested, I replaced the line

voice.play(discord.FFmpegPCMAudio(audio, after=lambda e: looptrack(ctx)))

with

voice.play(discord.FFmpegPCMAudio(audio), after=lambda e: looptrack(ctx))

which now throws a new error

Warning: coroutine 'Command.__call__' was never awaited
  self.after(error)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
1

There are 1 answers

3
Jasmijn On BEST ANSWER

Replace the line that gives an error with:

voice.play(discord.FFmpegPCMAudio(audio), after=lambda e: looptrack(ctx))

You put one closing parenthesis in the wrong place. after should be an argument to play, not FFmpegPCMAudio.