In the past few days I have started receiving an exception whenever the bot has connected to a voice channel causing the voice (playback) to abruptly cut out.
The exception is/was: interactions.client.errors.VoiceWebSocketClosed: The Websocket closed with code: 4020 - Unknown Error
The root cause of this problem was identified on the Discord Developer server here (for more info, etc.).
Apparently there has been a silent change in the Discord backend because it no longer accepts a string or a float for the d parameter of the payload in case of a heartbeat event.
Simply changing the way the random sequence is generated from random.uniform(0.0, 1.0) to random.getrandbits(64) in interactions/api/voice/voice_gateway.py fixes the issue.
Fixed version:
Connect to a voice channel. As soon as a heartbeat is sent the ws will close with code 4020.
Expected Results
Working voice functionality.
Minimal Reproducible Code
No response
Traceback
Task exception was never retrieved
future: <Task finished name='Task-88' coro=<ActiveVoiceState._ws_connect() done, defined at U:\src\sbdev\.venv\Lib\site-packages\interactions\models\internal\active_voice_state.py:105> exception=VoiceWebSocketClosed('The Websocket closed with code: 4020 - Unknown Error')>
Traceback (most recent call last):
File "U:\src\sbdev\.venv\Lib\site-packages\interactions\models\internal\active_voice_state.py", line 109, in _ws_connect
await self.ws.run()
File "U:\src\sbdev\.venv\Lib\site-packages\interactions\api\voice\voice_gateway.py", line 85, in run
msg = await receiving
^^^^^^^^^^^^^^^
File "U:\src\sbdev\.venv\Lib\site-packages\interactions\api\voice\voice_gateway.py", line 121, in receive
raise VoiceWebSocketClosed(resp.data)
interactions.client.errors.VoiceWebSocketClosed: The Websocket closed with code: 4020 - Unknown Error
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.
[X] I have attempted to debug this myself, and I believe this issue is with the library
Library Version
5.13.1
Describe the Bug
In the past few days I have started receiving an exception whenever the bot has connected to a voice channel causing the voice (playback) to abruptly cut out. The exception is/was:
interactions.client.errors.VoiceWebSocketClosed: The Websocket closed with code: 4020 - Unknown Error
The root cause of this problem was identified on the Discord Developer server here (for more info, etc.).Apparently there has been a silent change in the Discord backend because it no longer accepts a string or a float for the d parameter of the payload in case of a heartbeat event. Simply changing the way the random sequence is generated from
random.uniform(0.0, 1.0)
torandom.getrandbits(64)
ininteractions/api/voice/voice_gateway.py
fixes the issue. Fixed version:Steps to Reproduce
Connect to a voice channel. As soon as a heartbeat is sent the ws will close with code 4020.
Expected Results
Working voice functionality.
Minimal Reproducible Code
No response
Traceback
Checklist
Additional Information
No response