pycord
pycord copied to clipboard
voice receiving ends with not apparent reason
Summary
receiving voice works only for a short amount of time
Reproduction Steps
For reconstructing the problem join a voice channel together with the bot and start to speak until the voice data doesn't get printed anymore
Minimal Reproducible Code
import discord
import io
from discord.sinks import WaveSink as PycordWaveSink, Filters, AudioData
bot = discord.Bot()
class WaveSink(PycordWaveSink):
@Filters.container
def write(self, data, user):
if user not in self.audio_data:
file = io.BytesIO()
self.audio_data.update({user: AudioData(file)})
file = self.audio_data[user]
file.write(data)
print(data)
@bot.slash_command(guild_ids=[GUILD_ID])
async def join(ctx):
await ctx.author.voice.channel.connect()
await ctx.respond(f'listening to {ctx.author.name}', ephemeral=True)
bot.voice_clients[0].start_recording(WaveSink(), lambda x: x)
bot.run(TOKEN)
Expected Results
continuous voice receiving until it gets manually stopped
Actual Results
the voice receiving ends after a short amount of time leaving no stacktrace at all
Intents
discord.Intents.all()
System Information
- Python v3.8.5-final
- py-cord v2.0.0-beta
- py-cord pkg_resources: v2.0.0b4
- aiohttp v3.8.1
- system info: Windows 10 10.0.19041
Checklist
- [x] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.
Additional Context
https://stackoverflow.com/questions/72647225/voice-receiving-ends-for-no-apparent-reason
Please update pycord
Does this still happen?
Does this still happen?
Still having this problem on both the release and the development version
It appears the voice client loses connection after not sending data so my solution is playing silence to keep the connection alive.
class SilenceAudioSource(AudioSource):
def read(self) -> bytes:
return b'0' * 3840
self.vc.play(SilenceAudioSource())
self.vc.start_recording(
...