From e315cfbc1d7c36e667bd39c5c05ccc7e4d4def9d Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Sun, 13 Sep 2026 01:14:07 +0300 Subject: [PATCH] no more multi voice --- src/music/PlayerLifecycleMixin.mjs | 41 ++++++++++++++++++++++++++++++ storage/locales/bot/ar-SA.json | 4 +-- storage/locales/bot/ckb.json | 4 +-- storage/locales/bot/de-DE.json | 4 +-- storage/locales/bot/en.json | 4 +-- storage/locales/bot/pt-BR.json | 4 +-- storage/locales/bot/tr.json | 4 +-- 7 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/music/PlayerLifecycleMixin.mjs b/src/music/PlayerLifecycleMixin.mjs index 9d31436..971a51d 100644 --- a/src/music/PlayerLifecycleMixin.mjs +++ b/src/music/PlayerLifecycleMixin.mjs @@ -291,6 +291,47 @@ const PlayerLifecycleMixin = { } const cleanChannelId = cleanId(cid); + const targetGuildId = cleanId(channel.guildId ?? getMessageGuildId(message)); + + // --- Single-voice-channel-per-server enforcement --- + // The bot may only occupy one voice channel per guild at a time. If it's + // already active in a *different* channel in this guild, either refuse + // (busy: actively playing, or parked in 24/7) or silently relocate + // (idle: no queue, not 24/7) before joining the newly requested channel. + if (targetGuildId) { + const otherGuildPlayers = this.getGuildPlayers(targetGuildId) + .filter(([chId]) => chId !== cleanChannelId); + + if (otherGuildPlayers.length > 0) { + const busyPlayers = otherGuildPlayers.filter(([, p]) => this._isPlayerBusy(p)); + + if (busyPlayers.length > 0) { + const playingPlayers = busyPlayers.filter(([, p]) => this._isPlayerActivelyPlaying(p)); + const relevantPlayers = playingPlayers.length > 0 ? playingPlayers : busyPlayers; + const busyChannelList = relevantPlayers + .map(([chId, p]) => `<#${getPlayerChannelId(p, chId)}>`) + .join(" or "); + const prefix = this.commands.getPrefix(targetGuildId); + const key = playingPlayers.length > 0 + ? "responses._common.busyPlayingInOtherVoiceChannel" + : "responses._common.busyStayingInOtherVoiceChannel"; + message.reply(this._t(message, key, { channels: busyChannelList, prefix })); + return null; + } + + for (const [oldChannelId, oldPlayer] of otherGuildPlayers) { + this.playerMap.delete(oldChannelId); + this._unindexPlayer(targetGuildId, oldChannelId); + const pendingScrobble = this._pendingScrobbleTimers.get(oldChannelId); + if (pendingScrobble) { clearTimeout(pendingScrobble.timer); this._pendingScrobbleTimers.delete(oldChannelId); } + try { await oldPlayer.leave(); } catch (e) { + logger.warn("[PlayerManager] Error leaving idle channel during relocation:", e?.message); + } + try { oldPlayer.destroy(); } catch (_) {} + } + } + } + const existing = this.playerMap.get(cleanChannelId) ?? this.getPlayerByChannelId(cleanChannelId); if (existing) { diff --git a/storage/locales/bot/ar-SA.json b/storage/locales/bot/ar-SA.json index 0f65e21..89ac1be 100644 --- a/storage/locales/bot/ar-SA.json +++ b/storage/locales/bot/ar-SA.json @@ -202,8 +202,8 @@ "noVoiceChannel": "⚠️ يرجى الانضمام إلى قناة صوتية أولاً.", "noVoiceStrict": "⚠️ يجب عليك الانضمام إلى قناة صوتية لاستخدام هذا الأمر.", "alreadyInChannel": "⚠️ أنا أعزف بالفعل في {{channels}}. انضم إلى تلك القناة أو استخدم `{{prefix}}play` لبدء الموسيقى في قناتك.", - "busyPlayingInOtherVoiceChannel": "🎵 أقوم حاليًا بتشغيل الموسيقى في قناة صوتية أخرى: {{channels}}!\n🎧 **انضم إلى تلك القناة** للاستماع.\n💡 أو استخدم `{{prefix}}join` إذا كنت تريد أن أنتقل إلى قناتك.", - "busyStayingInOtherVoiceChannel": "🤖 أنا حاليًا في قناة صوتية أخرى: {{channels}} (وضع 24/7).\n🎧 انضم إلى تلك القناة لتكون معي، أو استخدم `{{prefix}}join` لنقلي إلى قناتك.", + "busyPlayingInOtherVoiceChannel": "🎵 **أنا بالفعل أشغّل الموسيقى في {{channels}}!**\n🎧 **انضم إلى تلك القناة** للاستماع معي.\n⏳ تريدني في قناتك بدلاً من ذلك؟ دع قائمة الانتظار تنتهي، أو امسحها باستخدام `{{prefix}}clear`، ثم استخدم `{{prefix}}join` مرة أخرى.\n🔧 يمكن لمشرفي السيرفر تجاوز هذا في أي وقت باستخدام `{{prefix}}forceleave`.", + "busyStayingInOtherVoiceChannel": "🤖 **أنا متوقف في {{channels}} في وضع 24/7.**\n🎧 انضم إلى تلك القناة لتكون معي.\n🔧 لإحضاري إلى قناتك بدلاً من ذلك، أوقف وضع 24/7 هناك باستخدام `{{prefix}}247 off`، أو اطلب من مشرف السيرفر تشغيل `{{prefix}}forceleave`.", "notInVoice": "أنا لست في قناة صوتية.", "queueEmpty": "📭 قائمة الانتظار فارغة. استخدم `{{prefix}}play` لإضافة أغاني!", "queueEnded": "🎵 قائمة الانتظار انتهت — لا يوجد شيء لتشغيله. أضف المزيد من الأغاني باستخدام `{{prefix}}play`!", diff --git a/storage/locales/bot/ckb.json b/storage/locales/bot/ckb.json index 54a859d..fef71ac 100644 --- a/storage/locales/bot/ckb.json +++ b/storage/locales/bot/ckb.json @@ -202,8 +202,8 @@ "noVoiceChannel": "⚠️ تکایە سەرەتا بەشداری کەناڵێکی دەنگی بکە.", "noVoiceStrict": "⚠️ پێویستە سەرەتا بەشداری کەناڵێکی دەنگی بکەیت بۆ بەکارهێنانی ئەم فەرمانە.", "alreadyInChannel": "⚠️ من پێشتر لە {{channels}} پەخش دەکەم. بەشداری ئەو کەناڵە بکە یان `{{prefix}}play` بەکاربهێنە بۆ دەستپێکردنی موزیک لە کەناڵەکەت.", - "busyPlayingInOtherVoiceChannel": "🎵 ئێستا لە کەناڵێکی دەنگی دیکە مۆزیک لێدەدەم: {{channels}}!\n🎧 **بەشداری ئەو کەناڵە بکە** بۆ گوێگرتن.\n💡 یان `{{prefix}}join` بەکاربهێنە ئەگەر دەتەوێت بگوازرێمەوە بۆ کەناڵەکەت.", - "busyStayingInOtherVoiceChannel": "🤖 ئێستا لە کەناڵێکی دەنگی دیکە دەمێنمەوە: {{channels}} (دۆخی 24/7).\n🎧 بۆ ئەوەی لەگەڵم بیت بەشداری ئەو کەناڵە بکە، یان `{{prefix}}join` بەکاربهێنە بۆ گواستنەوەم بۆ کەناڵەکەت.", + "busyPlayingInOtherVoiceChannel": "🎵 **ئێستا مۆزیکم لێدەدا لە {{channels}}!**\n🎧 **بەشداری ئەو کەناڵە بکە** بۆ گوێگرتن لەگەڵم.\n⏳ دەتەوێت لە کەناڵەکەی خۆت بم؟ با نۆرەکە تەواو بێت، یان بە `{{prefix}}clear` پاکی بکەرەوە، پاشان دووبارە `{{prefix}}join` بەکاربهێنە.\n🔧 بەڕێوەبەرانی سێرڤەر دەتوانن لە هەر کاتێکدا ئەمە پشتگوێ بخەن بە بەکارهێنانی `{{prefix}}forceleave`.", + "busyStayingInOtherVoiceChannel": "🤖 **لە کەناڵی {{channels}} لە دۆخی 24/7 مامەوە.**\n🎧 بەشداری ئەو کەناڵە بکە بۆ ئەوەی لەگەڵم بیت.\n🔧 بۆ ئەوەی بمهێنیتەوە بۆ کەناڵەکەت، دۆخی 24/7 لەوێ بە `{{prefix}}247 off` داخە، یان داوا لە بەڕێوەبەرێکی سێرڤەر بکە کە `{{prefix}}forceleave` جێبەجێ بکات.", "notInVoice": "من لە کەناڵێکی دەنگیدا نییم.", "queueEmpty": "📭 ڕیزبەندییەکە بەتاڵە. `{{prefix}}play` بەکاربهێنە بۆ زیادکردنی گۆرانی!", "queueEnded": "🎵 ڕیزبەندییەکە تەواو بوو — هیچ شتێک نەماوە بۆ پەخشکردن. گۆرانی زیاتر زیاد بکە بە `{{prefix}}play`!", diff --git a/storage/locales/bot/de-DE.json b/storage/locales/bot/de-DE.json index 8e34268..391beb9 100644 --- a/storage/locales/bot/de-DE.json +++ b/storage/locales/bot/de-DE.json @@ -202,8 +202,8 @@ "noVoiceChannel": "⚠️ Bitte trete zuerst einem Sprachkanal bei.", "noVoiceStrict": "⚠️ Du musst einem Sprachkanal beitreten, um diesen Befehl zu nutzen.", "alreadyInChannel": "⚠️ Ich spiele bereits in {{channels}}. Trete diesem Kanal bei oder nutze `{{prefix}}play`, um Musik in deinem Kanal zu starten.", - "busyPlayingInOtherVoiceChannel": "🎵 Ich spiele gerade Musik in einem anderen Sprachkanal: {{channels}}!\n🎧 **Tritt diesem Kanal bei**, um mitzuhören.\n💡 Oder benutze `{{prefix}}join`, wenn ich in deinen Kanal wechseln soll.", - "busyStayingInOtherVoiceChannel": "🤖 Ich halte mich gerade in einem anderen Sprachkanal auf: {{channels}} (24/7-Modus).\n🎧 Tritt diesem Kanal bei, um bei mir zu sein, oder benutze `{{prefix}}join`, um mich in deinen Kanal zu holen.", + "busyPlayingInOtherVoiceChannel": "🎵 **Ich spiele bereits Musik in {{channels}}!**\n🎧 **Tritt diesem Kanal bei**, um mitzuhören.\n⏳ Möchtest du mich stattdessen in deinem Kanal haben? Lass die Warteschlange zu Ende laufen oder leere sie mit `{{prefix}}clear`, und führe dann erneut `{{prefix}}join` aus.\n🔧 Servermanager können dies jederzeit mit `{{prefix}}forceleave` überschreiben.", + "busyStayingInOtherVoiceChannel": "🤖 **Ich bin in {{channels}} im 24/7-Modus geparkt.**\n🎧 Tritt diesem Kanal bei, um bei mir zu sein.\n🔧 Um mich stattdessen in deinen Kanal zu holen, deaktiviere dort den 24/7-Modus mit `{{prefix}}247 off`, oder bitte einen Servermanager, `{{prefix}}forceleave` auszuführen.", "notInVoice": "Ich bin in keinem Sprachkanal.", "queueEmpty": "📭 Die Warteschlange ist leer. Nutze `{{prefix}}play`, um Songs hinzuzufügen!", "queueEnded": "🎵 Die Warteschlange ist zu Ende — nichts mehr abzuspielen. Füge weitere Songs mit `{{prefix}}play` hinzu!", diff --git a/storage/locales/bot/en.json b/storage/locales/bot/en.json index 8478135..ca4b183 100644 --- a/storage/locales/bot/en.json +++ b/storage/locales/bot/en.json @@ -202,8 +202,8 @@ "noVoiceChannel": "⚠️ I can't find you in a voice channel. Please join one first, or if you're already in one, make sure I have **View Channel** and **Connect** permissions.", "noVoiceStrict": "⚠️ I can't find you in a voice channel. Please join one, or if you're already in one, make sure I have **View Channel** and **Connect** permissions.", "alreadyInChannel": "⚠️ I'm already playing in {{channels}}. Join that channel or use `{{prefix}}play` to start music in your channel.", - "busyPlayingInOtherVoiceChannel": "🎵 I'm already playing music in another voice channel: {{channels}}!\n🎧 **Join that channel** to listen along.\n💡 Or use `{{prefix}}join` if you want me to move to your channel instead.", - "busyStayingInOtherVoiceChannel": "🤖 I'm currently staying in another voice channel: {{channels}} (24/7 mode).\n🎧 Join that channel to hang out with me, or use `{{prefix}}join` to move me to your channel.", + "busyPlayingInOtherVoiceChannel": "🎵 **I'm already playing music in {{channels}}!**\n🎧 **Join that channel** to listen along.\n⏳ Want me in your channel instead? Let the queue finish, or clear it with `{{prefix}}clear`, then run `{{prefix}}join` again.\n🔧 Server managers can override this anytime with `{{prefix}}forceleave`.", + "busyStayingInOtherVoiceChannel": "🤖 **I'm parked in {{channels}} in 24/7 mode.**\n🎧 Join that channel to hang out with me.\n🔧 To bring me to your channel instead, turn off 24/7 there with `{{prefix}}247 off`, or ask a server manager to run `{{prefix}}forceleave`.", "notInVoice": "I'm not in a voice channel.", "queueEmpty": "📭 The queue is empty. Use `{{prefix}}play` to add songs!", "queueEnded": "🎵 The queue has ended — nothing left to play. Add more songs with `{{prefix}}play`!", diff --git a/storage/locales/bot/pt-BR.json b/storage/locales/bot/pt-BR.json index e070c04..98c79b0 100644 --- a/storage/locales/bot/pt-BR.json +++ b/storage/locales/bot/pt-BR.json @@ -202,8 +202,8 @@ "noVoiceChannel": "⚠️ Por favor, entre em um canal de voz primeiro.", "noVoiceStrict": "⚠️ Você precisa entrar em um canal de voz para usar este comando.", "alreadyInChannel": "⚠️ Já estou tocando em {{channels}}. Entre nesse canal ou use `{{prefix}}play` para começar a tocar no seu canal.", - "busyPlayingInOtherVoiceChannel": "🎵 Já estou tocando música em outro canal de voz: {{channels}}!\n🎧 **Entre nesse canal** para ouvir junto.\n💡 Ou use `{{prefix}}join` se quiser que eu mude para o seu canal.", - "busyStayingInOtherVoiceChannel": "🤖 No momento estou em outro canal de voz: {{channels}} (modo 24/7).\n🎧 Entre nesse canal para ficar comigo, ou use `{{prefix}}join` para me mover para o seu canal.", + "busyPlayingInOtherVoiceChannel": "🎵 **Já estou tocando música em {{channels}}!**\n🎧 **Entre nesse canal** para ouvir junto.\n⏳ Quer que eu vá para o seu canal? Deixe a fila terminar, ou limpe-a com `{{prefix}}clear`, e depois use `{{prefix}}join` novamente.\n🔧 Administradores do servidor podem substituir isso a qualquer momento com `{{prefix}}forceleave`.", + "busyStayingInOtherVoiceChannel": "🤖 **Estou parado em {{channels}} no modo 24/7.**\n🎧 Entre nesse canal para ficar comigo.\n🔧 Para me trazer para o seu canal, desative o modo 24/7 lá com `{{prefix}}247 off`, ou peça a um administrador do servidor para usar `{{prefix}}forceleave`.", "notInVoice": "Não estou em um canal de voz.", "queueEmpty": "📭 A fila está vazia. Use `{{prefix}}play` para adicionar músicas!", "queueEnded": "🎵 A fila acabou — nada mais para tocar. Adicione mais músicas com `{{prefix}}play`!", diff --git a/storage/locales/bot/tr.json b/storage/locales/bot/tr.json index de44ff0..b3676d1 100644 --- a/storage/locales/bot/tr.json +++ b/storage/locales/bot/tr.json @@ -202,8 +202,8 @@ "noVoiceChannel": "⚠️ Lütfen önce bir ses kanalına katılın.", "noVoiceStrict": "⚠️ Bu komutu kullanmak için bir ses kanalına katılmanız gerekiyor.", "alreadyInChannel": "⚠️ Zaten {{channels}} kanalında çalıyorum. O kanala katılın veya kendi kanalınızda müzik başlatmak için `{{prefix}}play` kullanın.", - "busyPlayingInOtherVoiceChannel": "🎵 Şu anda başka bir ses kanalında müzik çalıyorum: {{channels}}!\n🎧 Dinlemek için **o kanala katıl**.\n💡 Benim senin kanalına geçmemi istiyorsan `{{prefix}}join` komutunu kullan.", - "busyStayingInOtherVoiceChannel": "🤖 Şu anda başka bir ses kanalında kalıyorum: {{channels}} (24/7 modu).\n🎧 Benimle vakit geçirmek için o kanala katıl ya da beni taşımak için `{{prefix}}join` komutunu kullan.", + "busyPlayingInOtherVoiceChannel": "🎵 **Zaten {{channels}} kanalında müzik çalıyorum!**\n🎧 Dinlemek için **o kanala katıl**.\n⏳ Benim yerine senin kanalına gelmemi mi istiyorsun? Sıranın bitmesini bekle ya da `{{prefix}}clear` ile temizle, sonra tekrar `{{prefix}}join` çalıştır.\n🔧 Sunucu yöneticileri bunu istedikleri zaman `{{prefix}}forceleave` ile geçersiz kılabilir.", + "busyStayingInOtherVoiceChannel": "🤖 **{{channels}} kanalında 24/7 modunda bekliyorum.**\n🎧 Benimle vakit geçirmek için o kanala katıl.\n🔧 Beni senin kanalına getirmek için orada 24/7 modunu `{{prefix}}247 off` ile kapat, ya da bir sunucu yöneticisinden `{{prefix}}forceleave` çalıştırmasını iste.", "notInVoice": "Bir ses kanalında değilim.", "queueEmpty": "📭 Kuyruk boş. Şarkı eklemek için `{{prefix}}play` kullanın!", "queueEnded": "🎵 Kuyruk bitti — çalacak bir şey kalmadı. Daha fazla şarkı eklemek için `{{prefix}}play` kullanın!",