From 603032f1dbeebef014122f1ecb62f241e7da2d46 Mon Sep 17 00:00:00 2001 From: Mikolaj Wojciech Gorski Date: Sat, 26 Jul 2025 18:35:55 +0200 Subject: [PATCH] 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 --- discord.js-selfbot-v13 | 2 +- src/services/commandHandler.js | 41 ++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/discord.js-selfbot-v13 b/discord.js-selfbot-v13 index 5014823..174c89f 160000 --- a/discord.js-selfbot-v13 +++ b/discord.js-selfbot-v13 @@ -1 +1 @@ -Subproject commit 5014823f695ddefdeba332450a59dfbc23b98b1b +Subproject commit 174c89f18e2171461d838b0c1586acbabb9be7e1 diff --git a/src/services/commandHandler.js b/src/services/commandHandler.js index 0041d26..42e38a3 100644 --- a/src/services/commandHandler.js +++ b/src/services/commandHandler.js @@ -412,11 +412,13 @@ class CommandHandler { return null; } - msg.channel.send("🔧 Testing voice server connectivity..."); + msg.channel.send("🔧 Testing basic voice server connectivity..."); try { 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, { 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; msg.channel.send( `✅ Voice connection successful!\n` + `• Connect time: ${connectTime}ms\n` + - `• Voice server: ${connection.voiceServerURL || "Unknown"}\n` + `• Status: ${connection.status}\n` + - `• Channel: ${voiceChannel.name}` + `• Channel: ${voiceChannel.name}\n` + + `• Authentication: ${ + connection.authentication ? "Ready" : "Pending" + }` ); // Disconnect after test setTimeout(() => { - connection.disconnect(); - }, 2000); + try { + connection.disconnect(); + } catch (e) { + console.log( + "[Docker] Error disconnecting test connection:", + e.message + ); + } + }, 3000); return { action: { @@ -448,11 +470,12 @@ class CommandHandler { }, }; } catch (error) { + const connectTime = Date.now() - testStart; msg.channel.send( - `❌ Voice connection failed!\n` + + `❌ Voice connection failed after ${connectTime}ms!\n` + `• Error: ${error.message}\n` + - `• This may indicate Discord voice server issues\n` + - `• Try again in a few minutes` + `• This indicates Discord voice server or network issues\n` + + `• Try switching voice channels or try again later` ); return {