-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Allow passing an awaitable after
function to AudioPlayer
#448
Conversation
This enables awaitable functions to be called after an audio file has finished playing in voice calls.
✔️ Deploy Preview for nextcord-gh-action ready! 🔨 Explore the source changes: b48e423 🔍 Inspect the deploy log: https://app.netlify.com/sites/nextcord-gh-action/deploys/62093273b5c1c00008f78969 😎 Browse the preview: https://deploy-preview-448--nextcord-gh-action.netlify.app |
@@ -36,7 +36,19 @@ | |||
import re | |||
import io | |||
|
|||
from typing import Any, Callable, Generic, IO, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not entirely obvious from the diff, but all that was changed here was Awaitable
being added.
CI failure appears unrelated to this code change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, I haven't tested.
*Edit, you should probably update the docs
After digging into asyncio some more, I found that @Skelmis thank you for the suggestion! I've updated the documentation in fbfab79 to note that coroutines may be passed. |
…oa/after_await
…#448) * Allow passing an awaitable after function to AudioPlayer This enables awaitable functions to be called after an audio file has finished playing in voice calls. * Scope acceptable functions to coroutines, not any awaitable * Update documentation to note after may be a coroutine
Summary
This enables awaitable (async) functions to be called after an audio file has finished playing in voice calls.
I have been long frustrated with needing to provide a non-awaitable function to
VoiceClient.play
, only to have that function need to useasyncio.run_coroutine_threadsafe
to further call async code.By checking whether we receive an awaitable when calling
self.after
, and awaiting on it, we add support for awaitable functions.I have lightly tested this with success in my own Discord bot. Providing both async and non-async functions as the
after
arugment toVoiceClient.play
has resulted in them both being called successfully.Checklist