Monke
Monke
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
it's working now
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
thanks for the advices I did the check with connection.joinConfig.channelId to see if the event is tied to bot's VC and then made flags for player timeouts and used setTimeout/clearTimeout logic
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
actually nvm
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
can you help out? I'm out of ideas
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
so do I use connection.joinConfig.channelId for that check?
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
until a user leaves and rejoins
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
I tried this
client.on('voiceStateUpdate', (oldState, newState) => {
const guildId = newState.guild.id;

const connection = getVoiceConnection(guildId);
const player = audioPlayers.get(guildId);

try {
if (player && connection) {
const members = newState.channel?.members;

if (!members || (members.size === 1 && player.state.status === AudioPlayerStatus.Playing)) {
// If there's a scheduled pause, clear it
if (player.pauseTimeout) {
clearTimeout(player.pauseTimeout);
player.pauseTimeout = null;
}
// Schedule a pause after 3 seconds
player.pauseTimeout = setTimeout(() => {
player.pause();
console.log("!!Pausing!!");
}, 3000); // 3 seconds delay
} else if (members && members.size > 1 && player.state.status === AudioPlayerStatus.Paused) {
// Clear the scheduled pause if someone joins the voice channel
if (player.pauseTimeout) {
clearTimeout(player.pauseTimeout);
player.pauseTimeout = null;
}
player.unpause();
console.log("!!Unpausing!!");
}
}
} catch (err) {
console.error('Error: ', err);
}
});
client.on('voiceStateUpdate', (oldState, newState) => {
const guildId = newState.guild.id;

const connection = getVoiceConnection(guildId);
const player = audioPlayers.get(guildId);

try {
if (player && connection) {
const members = newState.channel?.members;

if (!members || (members.size === 1 && player.state.status === AudioPlayerStatus.Playing)) {
// If there's a scheduled pause, clear it
if (player.pauseTimeout) {
clearTimeout(player.pauseTimeout);
player.pauseTimeout = null;
}
// Schedule a pause after 3 seconds
player.pauseTimeout = setTimeout(() => {
player.pause();
console.log("!!Pausing!!");
}, 3000); // 3 seconds delay
} else if (members && members.size > 1 && player.state.status === AudioPlayerStatus.Paused) {
// Clear the scheduled pause if someone joins the voice channel
if (player.pauseTimeout) {
clearTimeout(player.pauseTimeout);
player.pauseTimeout = null;
}
player.unpause();
console.log("!!Unpausing!!");
}
}
} catch (err) {
console.error('Error: ', err);
}
});
and it does pause after 3 seconds but if someone joins in that 3 second interval bot still proceeds to pause and then doesn't resume playback
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
can anyone help?
11 replies
DIAdiscord.js - Imagine an app
Created by Monke on 10/31/2023 in #djs-voice
Player Auto-Pause
my discord.js version: [email protected] my node version: v20.1.0
11 replies