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

voice connection says it timed out, despite bot visibly joining in the voice channel #4302

Closed
1 task
zimmah opened this issue May 19, 2020 · 8 comments
Closed
1 task

Comments

@zimmah
Copy link

zimmah commented May 19, 2020

Please describe the problem you are having in as much detail as possible:
Background:
I have a bot that should play a very short sound when a timer runs out. This bot runs in multiple servers and should serve multiple groups per server (each with their own textchannel and voice channel). When the timer for a group runs out, it should connect to the voice channel of that group, play a very short sound, and disconnect. Then it should be ready to repeat the process.

The problem is, quite often it would just connect, say the connection timed out, and crash. Sometimes crashing the whole bot in the process.

 (node:23) UnhandledPromiseRejectionWarning: Error [VOICE_CONNECTION_TIMEOUT]: Connection not established within 15 seconds.
2020-05-19T12:18:59.877314+00:00 app[worker.1]: at VoiceConnection.authenticateFailed (/app/node_modules/discord.js/src/client/voice/VoiceConnection.js:304:26)
2020-05-19T12:18:59.877315+00:00 app[worker.1]: at /app/node_modules/discord.js/src/client/voice/VoiceConnection.js:325:61
2020-05-19T12:18:59.877316+00:00 app[worker.1]: at Timeout.<anonymous> (/app/node_modules/discord.js/src/client/BaseClient.js:83:7)

This is one error, but after that, sometimes it has another, much longer error, like this:

message: 'WebSocket was closed before the connection was established',
2020-05-19T12:19:25.426020+00:00 app[worker.1]: error: Error: WebSocket was closed before the connection was established
2020-05-19T12:19:25.426021+00:00 app[worker.1]: at WebSocket.close (/app/node_modules/ws/lib/websocket.js:220:14)
2020-05-19T12:19:25.426021+00:00 app[worker.1]: at VoiceWebSocket.reset (/app/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:53:60)
2020-05-19T12:19:25.426022+00:00 app[worker.1]: at VoiceWebSocket.shutdown (/app/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:44:10)
2020-05-19T12:19:25.426022+00:00 app[worker.1]: at VoiceConnection.cleanup (/app/node_modules/discord.js/src/client/voice/VoiceConnection.js:393:10)
2020-05-19T12:19:25.426023+00:00 app[worker.1]: at VoiceConnection._disconnect (/app/node_modules/discord.js/src/client/voice/VoiceConnection.js:368:10)

Include a reproducible code sample here, if possible:

let isVoiceBusy = false;
const queue = [];

const playNext = async (msg) => {
    isVoiceBusy = true;
    const next = queue.shift();
    const voiceChannel = msg.guild.channels.cache.find(channel => channel.name === next);
    try {
        const connection = await voiceChannel.join();
        const dispatcher = connection.play('./sounds/honk-sound.mp3');
        dispatcher.on('finish', () => {
            connection.disconnect();
            dispatcher.destroy();
            if (queue.length > 0) {
                setTimeout(() => playNext(msg), 500);
            } else {
                setTimeout(() => isVoiceBusy = false, 500);
                
            }
        });
    } catch (error) {

    }
}

const honk = (msg, mob) => {
    queue.push(mob.mobName); // the mobName corresponds to the voice channel name
    if (!isVoiceBusy) playNext(msg);
}

Further details:

  • discord.js version: ^12.2.0

  • Node.js version: 14.2.0

  • Operating system: windows 10

  • Priority this issue should have – please be realistic and elaborate if possible: medium. It's pretty annoying because it crashes the bot, and even though the bot could work without sound, it does cut out a pretty important feature.

  • I have also tested the issue on latest master, commit hash:

@zimmah
Copy link
Author

zimmah commented May 19, 2020

Note that it also sometimes complains about 'Unexpected server response: 525'

@ObscuritySRL
Copy link
Contributor

@zimmah - It sounds like your client options is missing GUILD_VOICE_STATES in the ws intents.

@DELUUXE
Copy link

DELUUXE commented Jun 3, 2020

im also seeing a few of these 'Unexpected server response: 525' errors about a week ago,
this does seem to have decreased now, maybe that one was related to some server-side change at discord.
i do have the GUILD_VOICE_STATES ws intent defined

@zimmah
Copy link
Author

zimmah commented Jun 19, 2020

The weird thing is it that it often works fine, but then sometimes it suddenly doesn't. It's a little unreliable, that's why it seems like a bug.

@CShigaki
Copy link

I'm also dealing with this problem. A workaround for it is waiting 5 seconds after leaving and before joining another channel

@Nathan-Search
Copy link

Try to regenerate the token in the developer website

@jerardoauiniga
Copy link

  • [ ]

@amishshah
Copy link
Member

Hi there,

We're working on a new implementation of Discord's Voice API that has better playback quality and is more reliable than what we currently support in Discord.js v12 - check it out at https://github.com/discordjs/voice!

The new library solves many of the issues that users are facing, and as part of this, we're dropping built-in support for voice in our next major release. We have a PR (#5402) that adds native support for our new voice library - once this PR is merged, this issue will be closed.

You can still use our new voice library before that PR lands - just take a look at our music bot example to see how to get started upgrading your voice code. By using the boilerplate music player in the example, you can make it even easier to upgrade your code.

Note that the PR above only reduces some of the boilerplate code you'd otherwise have to write - you do not have to wait for the PR to be merged to start using the new voice library.


If you have any questions about this, feel free to:

  • Make an issue if you have found a bug in the new voice library
  • Use GitHub Discussions or join our Discord server (we have a new channel, #djs-new-voice, specifically for this!) to ask general questions about the library, give feedback on the library, and get support with upgrading to it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants