hey, try using asyncio.create_task in your handler instead of asyncio.run. mixing loops causes issues, so rely on your bot’s loop to schedule download_clip. hope it helps!
In my experience, integrating asynchronous functions within a Telegram bot using a single event loop is crucial. The issue often arises when asyncio.run attempts to create a new loop rather than utilizing an existing one. Instead, extract the running loop from your bot’s context and schedule your download tasks as future objects. This structure avoids conflicts and ensures that all asynchronous operations are properly managed by the same event loop, leading to more predictable behavior and fewer errors.
After working on a similar project integrating async tasks in my own bot, I found that trying to spin up a separate event loop using asyncio.run was my biggest pitfall. I managed to resolve it by tapping into the existing event loop of the bot framework instead of starting a new one. By scheduling the download tasks as async tasks on the ongoing loop, I eliminated the errors. It required a bit of refactoring but ultimately resulted in a cleaner and more resilient integration between the TikTok API and the Telegram bot.