0

I'm building a bot with discord.py and i have encountered a problem with lambda and async. In particular i don't know how to fit a "Async lambda", if it possible, in the play function. This is the actual code:

async def play(...):
    ...
    voice.play(discord.FFmpegOpusAudio(source=self.song_path), 
               after=lambda e: self.play_next(ctx))

async def play_next(...):
    ...
    vc.play(discord.FFmpegPCMAudio(
            source=self.song_path),
            after=lambda e: self.play_next(ctx))
    await ctx.send(embed=Utility.get_embed("Now Playing", self.song_queue))

And this is the problem

coroutine 'main_bot.play_next' was never awaited self.after(error) RuntimeWarning: Enable tracemalloc to get the object allocation traceback*

EDIT: working answer in comments

Gino_P
  • 74
  • 7
  • 3
    Does this answer your question? [How to use await in a python lambda](https://stackoverflow.com/questions/40746213/how-to-use-await-in-a-python-lambda) – Ceres Apr 30 '21 at 06:37
  • 1
    Take a look at [How do I pass a coroutine to the player’s after function?](https://discordpy.readthedocs.io/en/latest/faq.html#how-do-i-pass-a-coroutine-to-the-player-s-after-function) – Łukasz Kwieciński Apr 30 '21 at 06:39

0 Answers0