Skip to content
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

feat: VoiceClient.play wait_finish parameter for awaiting end of stream #2194

Merged
merged 9 commits into from Aug 13, 2023

Conversation

davidhozic
Copy link
Contributor

@davidhozic davidhozic commented Aug 3, 2023

Summary

Added wait_finishparameter to VoiceClient.play, which will return an awaitable if True, that can be used to wait for the audio to stop playing. If set to False (default), the function will not block and None will be returned

Example:

import discord
import secret

client = discord.Client()

@client.listen("on_ready")
async def start():
    guild = client.get_guild(863071397207212052)

    channel: discord.VoiceChannel = guild.get_channel(1132373179210399844)

    def callback(exc):
        pass

    voice_client = await channel.connect()
    res = await voice_client.play(
        discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("VoiceMessage.mp3"), 0.25),
        after=callback,
        wait_finish=True
    )
    print(f"Set exception: {res}")

    voice_client.play(
        discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("VoiceMessage.mp3"), 0.25),
        after=callback,
        wait_finish=False
     )

client.run(secret.TOKEN)

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@davidhozic davidhozic marked this pull request as ready for review August 3, 2023 18:51
@davidhozic davidhozic requested a review from a team as a code owner August 3, 2023 18:51
@pullapprove4 pullapprove4 bot requested a review from Middledot August 3, 2023 18:52
@davidhozic davidhozic changed the title feat: wait_end method to VoiceClient for awaiting audio to stop playing feat: VoiceClient.wait_end(timeout) method for waiting on audio to stop playing Aug 3, 2023
@davidhozic davidhozic changed the title feat: VoiceClient.wait_end(timeout) method for waiting on audio to stop playing feat: VoiceClient.wait_end method for waiting on audio to stop playing Aug 3, 2023
@davidhozic davidhozic marked this pull request as draft August 3, 2023 21:21
@davidhozic davidhozic changed the title feat: VoiceClient.wait_end method for waiting on audio to stop playing feat: VoiceClien wait_finish parameter for awaiting audio end Aug 3, 2023
@davidhozic davidhozic changed the title feat: VoiceClien wait_finish parameter for awaiting audio end feat: VoiceClient wait_finish parameter for awaiting audio end Aug 3, 2023
@davidhozic davidhozic changed the title feat: VoiceClient wait_finish parameter for awaiting audio end feat: VoiceClient.play wait_finish parameter for awaiting audio end Aug 3, 2023
@davidhozic davidhozic changed the title feat: VoiceClient.play wait_finish parameter for awaiting audio end feat: VoiceClient.play wait_finish parameter for awaiting end of stream Aug 3, 2023
@davidhozic davidhozic marked this pull request as ready for review August 3, 2023 21:39
Copy link
Member

@Middledot Middledot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, could be useful

@Lulalaby Lulalaby merged commit 017e4ad into Pycord-Development:master Aug 13, 2023
26 checks passed
@davidhozic davidhozic deleted the feat/wait_for_audio branch August 13, 2023 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants