diff --git a/dave/bot.mjs b/dave/bot.mjs index ad9c3d8..1904591 100644 --- a/dave/bot.mjs +++ b/dave/bot.mjs @@ -205,7 +205,13 @@ async function joinChannel(guildId, channelId) { const guild = await client.guilds.fetch(guildId).catch(() => null); const channel = guild && await guild.channels.fetch(channelId).catch(() => null); if (!channel || !channel.isVoiceBased()) { log(`join failed: ${guildId}/${channelId} not a voice channel`); return; } - if (currentGuildId && currentGuildId !== guildId) leaveChannel(); + if (currentGuildId === guildId && currentChannelId === channelId && getVoiceConnection(guildId)) { + log(`already in "${channel.name}"`); return; + } + // Always tear down any existing connection first. Re-subscribing a player and + // receiver onto a reused same-guild connection would stack duplicate speaking + // listeners (→ duplicate voice turns) and duplicate error handlers. + if (currentGuildId) leaveChannel(); const connection = joinVoiceChannel({ channelId, guildId, adapterCreator: guild.voiceAdapterCreator, selfDeaf: false, selfMute: false,