After disconnecting once, audio starts audibly buffering

Here is part of my /play command:
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.member.voice.channel.guild.voiceAdapterCreator,
});

const resource = createAudioResource("an mp3 live link", {
inlineVolume: true,
});

const player = createAudioPlayer();

connection.subscribe(player);
player.play(resource);

player.on("stateChange", async (oldState: any, newState: any) => {
log(`AudioPlayer: ${oldState.status} -> ${newState.status}`, "debug");

switch (newState.status) {
case AudioPlayerStatus.Idle:
log("The player has become idle.", "debug");
const resource = createAudioResource("an mp3 live link", {
inlineVolume: true,
});
player.play(resource);
break;
case AudioPlayerStatus.AutoPaused:
try {
await Promise.race([
entersState(player, AudioPlayerStatus.Idle, 2_000),
entersState(player, AudioPlayerStatus.Buffering, 2_000),
entersState(player, AudioPlayerStatus.Playing, 2_000),
]);
} catch {
connection.disconnect();
}
break;
}
});

connection.on("stateChange", async (oldState: any, newState: any) => {
log(`VoiceConnection: ${oldState.status} -> ${newState.status}`, "debug");

switch (newState.status) {
case VoiceConnectionStatus.Disconnected:
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 2_000),
entersState(connection, VoiceConnectionStatus.Connecting, 2_000),
]);
} catch (error) {
connection.destroy();
}
break;
case VoiceConnectionStatus.Destroyed:
player.stop();
break;
}
});
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.member.voice.channel.guild.voiceAdapterCreator,
});

const resource = createAudioResource("an mp3 live link", {
inlineVolume: true,
});

const player = createAudioPlayer();

connection.subscribe(player);
player.play(resource);

player.on("stateChange", async (oldState: any, newState: any) => {
log(`AudioPlayer: ${oldState.status} -> ${newState.status}`, "debug");

switch (newState.status) {
case AudioPlayerStatus.Idle:
log("The player has become idle.", "debug");
const resource = createAudioResource("an mp3 live link", {
inlineVolume: true,
});
player.play(resource);
break;
case AudioPlayerStatus.AutoPaused:
try {
await Promise.race([
entersState(player, AudioPlayerStatus.Idle, 2_000),
entersState(player, AudioPlayerStatus.Buffering, 2_000),
entersState(player, AudioPlayerStatus.Playing, 2_000),
]);
} catch {
connection.disconnect();
}
break;
}
});

connection.on("stateChange", async (oldState: any, newState: any) => {
log(`VoiceConnection: ${oldState.status} -> ${newState.status}`, "debug");

switch (newState.status) {
case VoiceConnectionStatus.Disconnected:
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 2_000),
entersState(connection, VoiceConnectionStatus.Connecting, 2_000),
]);
} catch (error) {
connection.destroy();
}
break;
case VoiceConnectionStatus.Destroyed:
player.stop();
break;
}
});
Now, this works flawlessly. But, when I initiate a connection.disconnect() - in a seperate command - it does indeed leave the voice channel. But when I run /play again, while it does play, it is very buffery. I believe what is happening is the old player hasn't been destroyed, and my computer is trying to play 2 streams? Maybe not? - GuildVoiceStates intent is enabled - Here is my dependencies:
Core Dependencies
- @discordjs/voice: 0.17.0
- prism-media: 1.3.5
Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: 0.1.1
Encryption Libraries
- sodium-native: not found
- sodium: 3.0.2
- libsodium-wrappers: 0.7.15
- tweetnacl: 1.0.3
FFmpeg
- version: 6.0-essentials_build-www.gyan.dev
- libopus: yes
Core Dependencies
- @discordjs/voice: 0.17.0
- prism-media: 1.3.5
Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: 0.1.1
Encryption Libraries
- sodium-native: not found
- sodium: 3.0.2
- libsodium-wrappers: 0.7.15
- tweetnacl: 1.0.3
FFmpeg
- version: 6.0-essentials_build-www.gyan.dev
- libopus: yes
6 Replies
d.js toolkit
d.js toolkit2mo ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
ted
tedOP2mo ago
Tried a few different things, still errors.
pat
pat2mo ago
errors or buffers?
ted
tedOP2mo ago
Sorry, been away for a few days. As far as I am aware from listening to error events there are no errors. I added some verbose logging. can't see what is going wrong...
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: signalling -> connecting
[DEBUG] AudioPlayer: buffering -> playing
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> ready
[DEBUG] AudioPlayer: autopaused -> playing
[DEBUG] Command: leave executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: ready -> disconnected
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: disconnected -> disconnected
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: disconnected -> destroyed
[DEBUG] The player has been stopped.
[WARN] Failed to destroy the connection: Error: Cannot destroy VoiceConnection - it has already been destroyed
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: signalling -> connecting
[DEBUG] AudioPlayer: buffering -> playing
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> ready
[DEBUG] AudioPlayer: autopaused -> playing
[DEBUG] Command: leave executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: ready -> disconnected
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: disconnected -> disconnected
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: disconnected -> destroyed
[DEBUG] The player has been stopped.
[WARN] Failed to destroy the connection: Error: Cannot destroy VoiceConnection - it has already been destroyed
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] AudioPlayer: buffering -> playing
[DEBUG] VoiceConnection: signalling -> connecting
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> ready
[DEBUG] AudioPlayer: autopaused -> playing
[DEBUG] Command: leave executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: ready -> disconnected
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: disconnected -> disconnected
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: disconnected -> destroyed
[DEBUG] The player has been stopped.
[WARN] Failed to destroy the connection: Error: Cannot destroy VoiceConnection - it has already been destroyed
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: signalling -> connecting
[DEBUG] AudioPlayer: buffering -> playing
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> ready
[DEBUG] AudioPlayer: autopaused -> playing
[DEBUG] Command: leave executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: ready -> disconnected
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: disconnected -> disconnected
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: disconnected -> destroyed
[DEBUG] The player has been stopped.
[WARN] Failed to destroy the connection: Error: Cannot destroy VoiceConnection - it has already been destroyed
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: signalling -> connecting
[DEBUG] AudioPlayer: buffering -> playing
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> ready
[DEBUG] AudioPlayer: autopaused -> playing
[DEBUG] Command: leave executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: ready -> disconnected
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: disconnected -> disconnected
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: disconnected -> destroyed
[DEBUG] The player has been stopped.
[WARN] Failed to destroy the connection: Error: Cannot destroy VoiceConnection - it has already been destroyed
[DEBUG] Command: play executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] AudioPlayer: buffering -> playing
[DEBUG] VoiceConnection: signalling -> connecting
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> connecting
[DEBUG] VoiceConnection: connecting -> ready
[DEBUG] AudioPlayer: autopaused -> playing
[DEBUG] Command: leave executed.
[DEBUG] Event: interactionCreate executed.
[DEBUG] VoiceConnection: ready -> disconnected
[DEBUG] AudioPlayer: playing -> autopaused
[DEBUG] VoiceConnection: disconnected -> disconnected
[DEBUG] Event: voiceStateUpdate executed.
[DEBUG] VoiceConnection: disconnected -> destroyed
[DEBUG] The player has been stopped.
[WARN] Failed to destroy the connection: Error: Cannot destroy VoiceConnection - it has already been destroyed
Maybe becasue it is a streamed mp3? I still think the connection is not being destroyed, and stays listening to the mp3 in memory or something...
pat
pat4w ago
shouldnt matter but i have no idea what the issue is if you turn off inlinevolume does anything change?
I believe what is happening is the old player hasn't been destroyed, and my computer is trying to play 2 streams? Maybe not?
the connection can only listen to one player and it prepares packets by reading the stream from the player, just to explain that "shouldnt matter" msg above there's no way i can think of that it would be reading from two players at once
ted
tedOP4w ago
No clue what is happening, still doing it.
Want results from more Discord servers?
Add your server