Repository: discordjs/voice (ts)

Issue:
I use the connection.disconnect() feature but it stays in VC.
**My bot is in VC. I try to disconnect it when there is no song playing. It doesn't leave or give an error.**

```js
const { getVoiceConnection } = require('@discordjs/voice');
const { MessageEmbed } = require('discord.js');

module.exports.run = async (bot, message, args, queue) => {
    if (!message.member.voice.channel) return message.channel.send({ content: `What? Excuse me? Do you really expect me to execute a MUSIC command without you being in a voice channel? Like how you gonna use them if you can't hear them bruh? Big brain much?` });

    if (queue === undefined) {
        const connection = getVoiceConnection(message.guild.id)
        connection.disconnect()
        message.channel.send({
            embeds: [new MessageEmbed()
                .setDescription("Thanks for tuning in!")
                .setColor("RED")
            ]
        })
        message.react("✅")
    } else {
        bot.distube.stop(message)
        message.react("✅")
        queue.voice.leave()
        message.channel.send({
            embeds: [new MessageEmbed()
                .setDescription("Thanks for tuning in!")
                .setColor("RED")
            ]
        })
    }
};
module.exports.config = {
    name: "disconnect",
    aliases: ["dc"]
}
```

**Further details:**

- @discordjs/voice version: 0.5.0
- Node.js version:14.17.1
- Operating system: Windows 10
- Priority this issue should have – please be realistic and elaborate if possible: not really at the top but is inconvinient.

**Relevant client options:**

- partials: none
- gateway intents: all
- other: none


Pull request description:
fix(VoiceConnection): disconnect method now actually disconnects
**Please describe the changes this PR makes and why it should be merged:**

Resolves #138.

Calling `VoiceConnection#disconnect()` didn't actually send the correct voice state update packet to Discord. This has been fixed to null the channelId before sending the packet, and a test exposing this has been added.

**Status and versioning classification:**

- Code changes have been tested against the Discord API, or there are no code changes

Patch:
diff --git a/src/VoiceConnection.ts b/src/VoiceConnection.ts
index 53bf94d..bb91e27 100644
--- a/src/VoiceConnection.ts
+++ b/src/VoiceConnection.ts
@@ -499,6 +499,7 @@ export class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
 		) {
 			return false;
 		}
+		this.joinConfig.channelId = null;
 		if (!this.state.adapter.sendPayload(createJoinVoiceChannelPayload(this.joinConfig))) {
 			this.state = {
 				adapter: this.state.adapter,


Test patch:
diff --git a/src/__tests__/VoiceConnection.test.ts b/src/__tests__/VoiceConnection.test.ts
index 1066c4e..35e873d 100644
--- a/src/__tests__/VoiceConnection.test.ts
+++ b/src/__tests__/VoiceConnection.test.ts
@@ -496,7 +496,17 @@ describe('VoiceConnection#disconnect', () => {
 			adapter,
 			networking: new Networking.Networking({} as any, false),
 		};
+		const leavePayload = Symbol('dummy');
+		DataStore.createJoinVoiceChannelPayload.mockImplementation(() => leavePayload as any);
 		expect(voiceConnection.disconnect()).toBe(true);
+		expect(voiceConnection.joinConfig).toMatchObject({
+			channelId: null,
+			guildId: '2',
+			selfDeaf: true,
+			selfMute: false,
+		});
+		expect(DataStore.createJoinVoiceChannelPayload).toHaveBeenCalledWith(voiceConnection.joinConfig);
+		expect(adapter.sendPayload).toHaveBeenCalledWith(leavePayload);
 		expect(voiceConnection.state).toMatchObject({
 			status: VoiceConnectionStatus.Disconnected,
 			reason: VoiceConnectionDisconnectReason.Manual,