Is It Possible To Put An Async Function As A Callable Argument?
I'm coding a music bot for my server, and I need to disconnect (a coroutine) when the queue is exhausted. So I use a try: except block to handle that, however, when using VoiceClie
Solution 1:
You can define a callback function that will schedule a coroutine to run on your event loop, wrap it into a partial
and pass that to the play
method instead.
from functools import partial
def _handle_error(loop, error):
asyncio.run_coroutine_threadsafe(playqueue(error), loop) # playqueue should be an async function
vcc.play(discord.FFmpegOpusAudio(executable=r"ffmpeg.exe", source=tfname), after=partial(_handle_error, vcc.loop)) # vcc.loop is your event loop instance
Post a Comment for "Is It Possible To Put An Async Function As A Callable Argument?"