discord.js: VoiceConnection stuck in signalling state about a minute after creating it
Which package is this bug report for?
voice
Issue description
I’ve noticed a bug that seems to affect also some other users (see #8482). All the VoiceConnection works as intended the first minute, and then stop playing anything. The player subscribed switch in AutoPaused and the connection stays signalling state indefinitely.
After looking at the code (https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts), it seems that the only way for it to go back to ready state is to receive a message from discord api, that then create events that can put status back in ready state.
But, if I understand correctly, this discord message never comes(line 335), so an event is not created through the function configureNetworking(line 338, 420), and the state cannot change to ready(line 484).
That’s a messy explanation, and maybe false btw, but I’ve tried my best to understand.
Code sample
let voice_connection = Voice.joinVoiceChannel({
adapterCreator: guild.voiceAdapterCreator,
guildId: guild_id,
channelId: channel_id,
selfDeaf: true,
selfMute: false
});
let player = new Voice.AudioPlayer({noSubscriber: Voice.NoSubscriberBehavior.Pause});
voice_connection.subscribe(player);
let resource = Voice.createAudioResource(local_file_or_stream);
player.play(resource);
Package version
14.7.0
Node.js version
18.7.0; 18.14.2; 19.7.0 and maybe others
Operating system
Windows, WSL, Ubuntu, Debian…
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
Not applicable (subpackage bug)
Which gateway intents are you subscribing to?
Guilds, GuildVoiceStates
I have tested this issue on a development release
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 25
- Comments: 63 (5 by maintainers)
Commits related to this issue
- Implemented discord fix from https://github.com/discordjs/discord.js/issues/9185#issuecomment-1450863604 — committed to alexrichard0598/Volfbot by alexrichard0598 a year ago
- Hotfix for https://github.com/discordjs/discord.js/issues/9185 — committed to brandon-doornbos/vibin by brandon-doornbos a year ago
- Bandaid fix (https://github.com/discordjs/discord.js/issues/9185) — committed to isiah-lloyd/RadiYo by isiah-lloyd a year ago
- workaround: remove keep alive signal (https://github.com/discordjs/discord.js/issues/9185#issuecomment-1452514375) — committed to y-chan/voicevox_discord_tts_bot by y-chan a year ago
- Implement new fix https://github.com/discordjs/discord.js/issues/9185#issuecomment-1452514375 — committed to brandon-doornbos/vibin by brandon-doornbos a year ago
- temporary fix for discord api voiceconnection problem Related issue: https://github.com/discordjs/discord.js/issues/9185 — committed to Soratz/kuroi by Soratz a year ago
- Voice connection workaround (https://github.com/discordjs/discord.js/issues/9185#issuecomment-1452514375) — committed to 2colours/rad.io by deleted user a year ago
- Mein メイド v1.6.9 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Mein メイド v1.6.9 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Fix: Discord Bot Disconnecting after a Min. Fixed: - Music Bot will no longer disconnect after a minute of play time. -- Applied to temporary code patch from https://github.com/discordjs/discord.js/i... — committed to DavidCarbon/evobot by DavidCarbon a year ago
- fix: https://github.com/discordjs/discord.js/issues/9185#issuecomment-1452514375 — committed to tochiu/present-mic by tochiu a year ago
- Currently (03/08/23) there's a bug in discords voice module which times out audio streams after roughly 1 minute. This should just be a temporary fix that will be removed when discord fixes the issue ... — committed to andrew-noah/discord-bot by andrew-noah a year ago
- Apply discord.js hotfix in https://github.com/discordjs/discord.js/issues/9185#issuecomment-1452514375 — committed to pedrovfranco/SpankMeBotty by pedrovfranco a year ago
- Mein メイド v1.6.10 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Mein メイド v1.6.10 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Mein メイド v1.6.10 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Mein メイド v1.6.10 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Mein メイド v1.6.10 Stable - Sending less GUI - fix the bug for discordjs:https://github.com/discordjs/discord.js/issues/9185#issuecomment-1453535500 - prepare for the web GUI — committed to DanielBUBU/PD_maid by DanielBUBU a year ago
- Update @discordjs/voice to a dev version to fix https://github.com/discordjs/discord.js/issues/9185 — committed to brandon-doornbos/vibin by brandon-doornbos a year ago
- Fix Infinite number of listeners 'UDP' hotfix Based off this comment https://github.com/discordjs/discord.js/issues/9185#issuecomment-1459083216 — committed to DavidCarbon/evobot by DavidCarbon a year ago
A workaround is to remove keepAlive timer/interval.
You can do this without patching
@discordjs/voicein node_modules.Simply put the following code for a voiceConnection object.
Thanks to @ramsydx for the updated version.
I wasn’t able to switch the region on the server so I made this as a temporary workaround:
The little pause is shorter then on this solution. Maybe this helps anyopne looking for a temporary solution.
Indeed it has been fixed! Slap that
npm i @discordjs/voice@latestin your terminal and (assuming npm cache doesn’t troll you and installs 0.14.0 still) it’ll be all gud!This way of writing would result in an infinite number of listeners being added. oldNetworking?.off() was not working. This is because it is not the function registered in the previous ‘on’.
Here is my proposal.
This has been fixed in v0.15.0 https://github.com/discordjs/discord.js/blob/%40discordjs%2Fvoice%400.15.0/packages/voice/CHANGELOG.md
After investigation I am sure that this is a bug in
@discordjs/voicethat affecting some voice servers.The
VoiceUDPSocketobject implemented some undocumentedkeepAlivefunctionality which sends a keepAlive counter packed in a 8-bytes data every 5 seconds interval, and it expects a reply from voice server.But somehow some of the voice servers out there did not response back with the keepAlive counter, resulting in the
keepAlivesarray to grow and eventually reach the 12 length limit, which took exactly 60 seconds.https://github.com/discordjs/discord.js/blob/dc142c47e4021d6d37712453cc2fad6e4fe4e9f7/packages/voice/src/networking/VoiceUDPSocket.ts#L39-L47
This code sets up the
keepAlivefunctionality. https://github.com/discordjs/discord.js/blob/dc142c47e4021d6d37712453cc2fad6e4fe4e9f7/packages/voice/src/networking/VoiceUDPSocket.ts#L117-L120This method expects a keepAlive counter data response from the voice server. https://github.com/discordjs/discord.js/blob/dc142c47e4021d6d37712453cc2fad6e4fe4e9f7/packages/voice/src/networking/VoiceUDPSocket.ts#L130-L143
Here are some debugging logs from
VoiceUDPSocketconnected tosingapore63voice server which affected by this issue.As you can see, there is no 8-bytes response and the
VoiceUDPSocket.destroy()method was called by thekeepAlivemethod.I managed to find an unaffected voice server which is
singapore11050, and here are the logsThe voice server did response back with expected data so
keepAlivesarray will never grow and I didn’t experience a disconnection from this server.I’ve also found a workaround to this problem :
Add
this.configureNetworking();on the line 355 of this file : https://github.com/discordjs/discord.js/blob/main/packages/voice/src/VoiceConnection.ts Or Addthis.configureNetworking();on the line 1361 of the file located at node_modules/@discordjs/voice/dist/index.jsAdd it after you create or get the voiceConnection. Ex:
Oof. Could you open an issue on their documentation repo and ask for inputs on what we should be doing? It’s really not ideal to have to just reverse engineer their clients just so bots can provide voice support ☹️
The discord voice documentation is a solid 3 versions behind. This is a non-exhaustive list of missing features:
I believe discord may be lazy in documenting their voice API as they do not see the need to.
Restarted my bot several times. Still same issue.
I have the same problem. It started to happen today without me changing anything in the code. So probably discord changing something on their side of the connection 🤔. @Theiremi your solution works for me but now i have a short pause every minute while playling.
I think it’s okay since it translates to “leet cafe” which makes me inclined to think Discord just wanted a magic number to differentiate heartbeats. If they changed it, it would brick all of their clients as well. I have checked a few months ago to find the same magic constant in their older module before they updated their voice servers. And either way, I believe it’s still best to patch the issue for now and work on a more “permanent” fix later.
This is a message from Discord Developers Server. .gg/discord-developers
Well if you don’t know how to write code, you propably don’t use this discord.js. But as there is at least one person that doesn’t know where to put this, you are probably right.
Put this after you created your connection. For me it looks something like this: