discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.38k stars 3.97k forks source link

Can't join a voiceChannel #5114

Closed julianortlieb closed 3 years ago

julianortlieb commented 3 years ago

Description

I tried to join a voice channel normaly with following code.

Code

        var voiceChannel = message.member?.voice ? message.member?.voice.channel : null;

        if(!voiceChannel)
            return await message.channel.send("You have to be in a voice channel!");

        var permissions: Readonly<Permissions> | null = null;
        if (message.client.user) {
            permissions = voiceChannel.permissionsFor(message.client.user);
        }

        if(!permissions?.has(Permissions.FLAGS.CONNECT) ||!permissions.has(Permissions.FLAGS.SPEAK))
            return await message.channel.send("I have no permissions for this.");

        try {
            var connection = await voiceChannel.join();
            console.log("joined");
        } catch (error) {
            console.log(error);
            return await message.channel.send(error.message);
        }

Console output

Console output with client.on('debug', console.log);

Strangely enough the session_ID is undefined here: [VOICE (***:2)]: Authenticated with sessionID undefined. All personal data are replaced by ***.

Provided token: xxx
Preparing to connect to the gateway...
[WS => Manager] Fetched Gateway Information
    URL: wss://gateway.discord.gg
    Recommended Shards: 1
[WS => Manager] Session Limit Information
    Total: 1000
    Remaining: 900
[WS => Manager] Spawning shards: 0
[WS => Shard 0] [CONNECT]
    Gateway    : wss://gateway.discord.gg/
    Version    : 6
    Encoding   : json
    Compression: none
[WS => Shard 0] Setting a HELLO timeout for 20s.
[WS => Shard 0] [CONNECTED] wss://gateway.discord.gg/?v=6&encoding=json in 280ms
[WS => Shard 0] Clearing the HELLO timeout.
[WS => Shard 0] Setting a heartbeat interval for 41250ms.
[WS => Shard 0] [IDENTIFY] Shard 0/1
[WS => Shard 0] [READY] Session ***.
[WS => Shard 0] [ReadyHeartbeat] Sending a heartbeat.
[WS => Shard 0] Shard received all its guilds. Marking as fully ready.
Logged in as ***
[WS => Shard 0] Heartbeat acknowledged, latency of 163ms.
Command from Client: startwelcome
[VOICE (***:2)]: Sending voice state update: {"guild_id":"***","channel_id":"***","self_mute":false,"self_deaf":false}
[VOICE] received voice server: {"t":"VOICE_SERVER_UPDATE","s":5,"op":0,"d":{"token":"***","guild_id":"***","endpoint":"eu-central5755.discord.media:443"}}
[VOICE] voiceServer guild: ***token: ***endpoint: eu-central5755.discord.media:443
[VOICE (***:2)]: Token "***" and endpoint "eu-central5755.discord.media:443"
[VOICE (***:2)]: Endpoint resolved as eu-central5755.discord.media
[VOICE (***:2)]: Authenticated with sessionID undefined
[VOICE (***:2)]: Authenticate failed - VOICE_CONNECTION_TIMEOUT
Error [VOICE_CONNECTION_TIMEOUT]: Connection not established within 15 seconds.
    at VoiceConnection.authenticateFailed (D:\Data\node_modules\discord.js\src\client\voice\VoiceConnection.js:296:27)
    at D:\Data\node_modules\discord.js\src\client\voice\VoiceConnection.js:324:61
    at Timeout.<anonymous> (D:\Data\node_modules\discord.js\src\client\BaseClient.js:83:7)
    at listOnTimeout (node:internal/timers:556:17)
    at processTimers (node:internal/timers:499:7) {
  [Symbol(code)]: 'VOICE_CONNECTION_TIMEOUT'
}  

Further details:

SpaceEEC commented 3 years ago

You seem to never be receiving the voice state update event for your client joining the voice channel.

Do you have the GUILD_VOICE_STATES intent enabled? (If you do not specify intents, you are fine)

Does the bot join the voice channel? (As-in in the Discord client you use)

Can you try logging client.ws.on('VOICE_STATE_UPDATE', console.log) and client.on('voiceStateUpdate', console.log);? (Do they log and if so what?)

julianortlieb commented 3 years ago

Ohh you are right. It was the intents that I had set incorrectly. I think the issue is done. Thanks!