[SOLVED] Playback ends after ~1 minute without any errors emitted

Title. It sometimes becomes Autopaused, sometimes not. It eventually becomes Idle after a few minutes. No errors are emitted from the player nor the connection. Any ideas on how I can get more information on what's going wrong or any solutions to problems I have overlooked? Thanks. The bot's connection and player are being initialized like this:
const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
loudspeakerClient.connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});

//init loudspeaker with queue
loudspeakerClient.queue = [];

//init player
loudspeakerClient.player = createAudioPlayer({
behaviors: {
//I have tried both .Pause and commenting the line out
noSubscriber: NoSubscriberBehavior.Play,
//idk what this does but I tried turning it on in case it would print errors
debug: true
}
});

//install event handlers (DEBUGGING)
loudspeakerClient.player.on(AudioPlayerStatus.Paused, () => {
console.log("PAUSED!");
});
loudspeakerClient.player.on(AudioPlayerStatus.Playing, () => {
console.log("PLAYING!");
});
loudspeakerClient.player.on(AudioPlayerStatus.Idle, () => {
console.log("IDLE!");
});
loudspeakerClient.player.on(AudioPlayerStatus.Buffering, () => {
console.log("BUFFERING!");
});
loudspeakerClient.player.on(AudioPlayerStatus.AutoPaused, () => {
console.log("AUTOPAUSED!");
});
loudspeakerClient.player.on('error', error => {
console.log(`Error: ${error.message}`);
});
loudspeakerClient.player.on('stateChange', (oldState, newState) => {
console.log(`${oldState.status} -> ${newState.status}`);
});
loudspeakerClient.connection.on('error', error => {
console.log(`Connection Error: ${error.message}`);
});
const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
loudspeakerClient.connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});

//init loudspeaker with queue
loudspeakerClient.queue = [];

//init player
loudspeakerClient.player = createAudioPlayer({
behaviors: {
//I have tried both .Pause and commenting the line out
noSubscriber: NoSubscriberBehavior.Play,
//idk what this does but I tried turning it on in case it would print errors
debug: true
}
});

//install event handlers (DEBUGGING)
loudspeakerClient.player.on(AudioPlayerStatus.Paused, () => {
console.log("PAUSED!");
});
loudspeakerClient.player.on(AudioPlayerStatus.Playing, () => {
console.log("PLAYING!");
});
loudspeakerClient.player.on(AudioPlayerStatus.Idle, () => {
console.log("IDLE!");
});
loudspeakerClient.player.on(AudioPlayerStatus.Buffering, () => {
console.log("BUFFERING!");
});
loudspeakerClient.player.on(AudioPlayerStatus.AutoPaused, () => {
console.log("AUTOPAUSED!");
});
loudspeakerClient.player.on('error', error => {
console.log(`Error: ${error.message}`);
});
loudspeakerClient.player.on('stateChange', (oldState, newState) => {
console.log(`${oldState.status} -> ${newState.status}`);
});
loudspeakerClient.connection.on('error', error => {
console.log(`Connection Error: ${error.message}`);
});
And playing back with:
//create resource from stream
const resource = createAudioResource(loudspeakerClient.songStream);
//play source
loudspeakerClient.player.play(resource);
//subscribe to player
loudspeakerClient.connection.subscribe(loudspeakerClient.player);
//create resource from stream
const resource = createAudioResource(loudspeakerClient.songStream);
//play source
loudspeakerClient.player.play(resource);
//subscribe to player
loudspeakerClient.connection.subscribe(loudspeakerClient.player);
14 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
CombustibleToast
CombustibleToastOP2y ago
[email protected] node v18.16.0
CombustibleToast
CombustibleToastOP2y ago
GitHub
SUCCESS: Bot stops playing after around 1 minute · Issue #97 · umut...
The bot stops playing after around 1 minute of playback... No error in the console. Any idea what could be causing this?
CombustibleToast
CombustibleToastOP2y ago
I needed to install the following event listener to the client (this is copy pasted from the comment modified a little to fit my code):
loudspeakerClient.connection.on('stateChange', (oldState, newState) => {
console.log(`connection state change: ${oldState} -> ${newState}`);
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');
const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}
oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});
loudspeakerClient.connection.on('stateChange', (oldState, newState) => {
console.log(`connection state change: ${oldState} -> ${newState}`);
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');
const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}
oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});
I put this directly below the call to joinVoiceChannel()
duck
duck2y ago
this fix should no longer be needed on the latest version of @discordjs/voice could you share your @discordjs/voice version?
CombustibleToast
CombustibleToastOP2y ago
0.11.0
duck
duck2y ago
latest is 0.16.0 consider updating
CombustibleToast
CombustibleToastOP2y ago
wow i shall thank you also may be relevant to @sayed1
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
CombustibleToast
CombustibleToastOP2y ago
amazing! though updating djs voice also fixes it i updated to latest and i removed the code
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
CombustibleToast
CombustibleToastOP2y ago
BTThumb
Alynva
Alynva14mo ago
Solved my problem too, ty!
CombustibleToast
CombustibleToastOP14mo ago
BTThumbMRVN
Want results from more Discord servers?
Add your server