feat: enhance voice connection testing with better timeout handling

- Add 45s manual timeout for connection testing
- Add Promise.race for better timeout control
- Enhanced error reporting with connection timing
- Better disconnect handling in test command
- More detailed connection success information
This commit is contained in:
Mikolaj Wojciech Gorski 2025-07-26 18:35:55 +02:00
parent c5cf8f0488
commit 603032f1db
2 changed files with 33 additions and 10 deletions

@ -1 +1 @@
Subproject commit 5014823f695ddefdeba332450a59dfbc23b98b1b Subproject commit 174c89f18e2171461d838b0c1586acbabb9be7e1

View file

@ -412,11 +412,13 @@ class CommandHandler {
return null; return null;
} }
msg.channel.send("🔧 Testing voice server connectivity..."); msg.channel.send("🔧 Testing basic voice server connectivity...");
try { try {
const testStart = Date.now(); const testStart = Date.now();
const connection = await context.client.voice.joinChannel(
// Simple connection test with timeout promise
const connectionPromise = context.client.voice.joinChannel(
voiceChannel.id, voiceChannel.id,
{ {
selfMute: true, selfMute: true,
@ -425,20 +427,40 @@ class CommandHandler {
} }
); );
const timeoutPromise = new Promise((_, reject) => {
setTimeout(
() => reject(new Error("Manual timeout after 45 seconds")),
45000
);
});
const connection = await Promise.race([
connectionPromise,
timeoutPromise,
]);
const connectTime = Date.now() - testStart; const connectTime = Date.now() - testStart;
msg.channel.send( msg.channel.send(
`✅ Voice connection successful!\n` + `✅ Voice connection successful!\n` +
`• Connect time: ${connectTime}ms\n` + `• Connect time: ${connectTime}ms\n` +
`• Voice server: ${connection.voiceServerURL || "Unknown"}\n` +
`• Status: ${connection.status}\n` + `• Status: ${connection.status}\n` +
`• Channel: ${voiceChannel.name}` `• Channel: ${voiceChannel.name}\n` +
`• Authentication: ${
connection.authentication ? "Ready" : "Pending"
}`
); );
// Disconnect after test // Disconnect after test
setTimeout(() => { setTimeout(() => {
try {
connection.disconnect(); connection.disconnect();
}, 2000); } catch (e) {
console.log(
"[Docker] Error disconnecting test connection:",
e.message
);
}
}, 3000);
return { return {
action: { action: {
@ -448,11 +470,12 @@ class CommandHandler {
}, },
}; };
} catch (error) { } catch (error) {
const connectTime = Date.now() - testStart;
msg.channel.send( msg.channel.send(
`❌ Voice connection failed!\n` + `❌ Voice connection failed after ${connectTime}ms!\n` +
`• Error: ${error.message}\n` + `• Error: ${error.message}\n` +
`• This may indicate Discord voice server issues\n` + `• This indicates Discord voice server or network issues\n` +
`• Try again in a few minutes` `• Try switching voice channels or try again later`
); );
return { return {