Add "bot busy in another voice channel" warning

This commit is contained in:
NoLogicAlan committed 2026-09-12 03:11:23 +03:00
1 parent 771b005d7e
commit 0107e745d3
7 files changed
+74

No files matched your search

+62
View File
@@ -125,6 +125,49 @@ export class PlayerManager {
return null; return null;
} }
/**
* Check whether a player counts as "busy" — i.e. the bot is actively
* serving that channel: a track is loaded (playing or paused), the queue
* still has songs, a radio stream is running, or the channel is parked in
* 24/7 (stay) mode. Used by {@link getPlayer} to warn users instead of
* silently moving the bot out of a channel where people are listening.
* @param {Player} player - The player to inspect.
* @returns {boolean} True if the player is playing/staying for its channel.
*/
_isPlayerBusy(player) {
if (!player || player._destroyed) return false;
try {
if (player._get247Mode?.() === "on") return true;
if (player.queue?.getCurrent?.()) return true;
if (player.queue && !player.queue.isEmpty()) return true;
if (player._wasRadio) return true;
} catch (e) {
logger.warn("[PlayerManager] _isPlayerBusy check failed:", e?.message);
}
return false;
}
/**
* Check whether a player is actively playing audio — a track is loaded
* (playing or paused), the queue still has songs, or a radio stream is
* running. Stricter than {@link _isPlayerBusy}, which also counts idle
* 24/7 stays. Picks which of the two "busy elsewhere" warnings to show:
* the "already playing music" one, or the "staying in 24/7 mode" one.
* @param {Player} player - The player to inspect.
* @returns {boolean} True if audio is actively playing (or paused).
*/
_isPlayerActivelyPlaying(player) {
if (!player || player._destroyed) return false;
try {
if (player.queue?.getCurrent?.()) return true;
if (player.queue && !player.queue.isEmpty()) return true;
if (player._wasRadio) return true;
} catch (e) {
logger.warn("[PlayerManager] _isPlayerActivelyPlaying check failed:", e?.message);
}
return false;
}
/** Find a player by its channel ID across all guilds. @param {string} channelId @returns {Player|null} */ /** Find a player by its channel ID across all guilds. @param {string} channelId @returns {Player|null} */
getPlayerByChannelId(channelId) { getPlayerByChannelId(channelId) {
const cId = cleanId(channelId); const cId = cleanId(channelId);
@@ -199,6 +242,25 @@ export class PlayerManager {
} }
if (shouldJoin) { if (shouldJoin) {
const busyPlayers = serverPlayers.filter(([, player]) => this._isPlayerBusy(player));
if (busyPlayers.length > 0) {
const playingPlayers = busyPlayers.filter(([, player]) => this._isPlayerActivelyPlaying(player));
const relevantPlayers = playingPlayers.length > 0 ? playingPlayers : busyPlayers;
const busyChannelList = relevantPlayers
.map(([chId, player]) => `<#${getPlayerChannelId(player, chId)}>`)
.join(" or ");
const prefix = this.commands.getPrefix(guildId);
const key = playingPlayers.length > 0
? "responses._common.busyPlayingInOtherVoiceChannel"
: "responses._common.busyStayingInOtherVoiceChannel";
message.reply(
this._t(message, key, {
channels: busyChannelList,
prefix,
})
);
return null;
}
return this.initPlayer(message, userChannelId); return this.initPlayer(message, userChannelId);
} }
+2
View File
@@ -202,6 +202,8 @@
"noVoiceChannel": "⚠️ يرجى الانضمام إلى قناة صوتية أولاً.", "noVoiceChannel": "⚠️ يرجى الانضمام إلى قناة صوتية أولاً.",
"noVoiceStrict": "⚠️ يجب عليك الانضمام إلى قناة صوتية لاستخدام هذا الأمر.", "noVoiceStrict": "⚠️ يجب عليك الانضمام إلى قناة صوتية لاستخدام هذا الأمر.",
"alreadyInChannel": "⚠️ أنا أعزف بالفعل في {{channels}}. انضم إلى تلك القناة أو استخدم `{{prefix}}play` لبدء الموسيقى في قناتك.", "alreadyInChannel": "⚠️ أنا أعزف بالفعل في {{channels}}. انضم إلى تلك القناة أو استخدم `{{prefix}}play` لبدء الموسيقى في قناتك.",
"busyPlayingInOtherVoiceChannel": "🎵 أقوم حاليًا بتشغيل الموسيقى في قناة صوتية أخرى: {{channels}}!\n🎧 **انضم إلى تلك القناة** للاستماع.\n💡 أو استخدم `{{prefix}}join` إذا كنت تريد أن أنتقل إلى قناتك.",
"busyStayingInOtherVoiceChannel": "🤖 أنا حاليًا في قناة صوتية أخرى: {{channels}} (وضع 24/7).\n🎧 انضم إلى تلك القناة لتكون معي، أو استخدم `{{prefix}}join` لنقلي إلى قناتك.",
"notInVoice": "أنا لست في قناة صوتية.", "notInVoice": "أنا لست في قناة صوتية.",
"queueEmpty": "📭 قائمة الانتظار فارغة. استخدم `{{prefix}}play` لإضافة أغاني!", "queueEmpty": "📭 قائمة الانتظار فارغة. استخدم `{{prefix}}play` لإضافة أغاني!",
"queueEnded": "🎵 قائمة الانتظار انتهت — لا يوجد شيء لتشغيله. أضف المزيد من الأغاني باستخدام `{{prefix}}play`!", "queueEnded": "🎵 قائمة الانتظار انتهت — لا يوجد شيء لتشغيله. أضف المزيد من الأغاني باستخدام `{{prefix}}play`!",
+2
View File
@@ -202,6 +202,8 @@
"noVoiceChannel": "⚠️ تکایە سەرەتا بەشداری کەناڵێکی دەنگی بکە.", "noVoiceChannel": "⚠️ تکایە سەرەتا بەشداری کەناڵێکی دەنگی بکە.",
"noVoiceStrict": "⚠️ پێویستە سەرەتا بەشداری کەناڵێکی دەنگی بکەیت بۆ بەکارهێنانی ئەم فەرمانە.", "noVoiceStrict": "⚠️ پێویستە سەرەتا بەشداری کەناڵێکی دەنگی بکەیت بۆ بەکارهێنانی ئەم فەرمانە.",
"alreadyInChannel": "⚠️ من پێشتر لە {{channels}} پەخش دەکەم. بەشداری ئەو کەناڵە بکە یان `{{prefix}}play` بەکاربهێنە بۆ دەستپێکردنی موزیک لە کەناڵەکەت.", "alreadyInChannel": "⚠️ من پێشتر لە {{channels}} پەخش دەکەم. بەشداری ئەو کەناڵە بکە یان `{{prefix}}play` بەکاربهێنە بۆ دەستپێکردنی موزیک لە کەناڵەکەت.",
"busyPlayingInOtherVoiceChannel": "🎵 ئێستا لە کەناڵێکی دەنگی دیکە مۆزیک لێدەدەم: {{channels}}!\n🎧 **بەشداری ئەو کەناڵە بکە** بۆ گوێگرتن.\n💡 یان `{{prefix}}join` بەکاربهێنە ئەگەر دەتەوێت بگوازرێمەوە بۆ کەناڵەکەت.",
"busyStayingInOtherVoiceChannel": "🤖 ئێستا لە کەناڵێکی دەنگی دیکە دەمێنمەوە: {{channels}} (دۆخی 24/7).\n🎧 بۆ ئەوەی لەگەڵم بیت بەشداری ئەو کەناڵە بکە، یان `{{prefix}}join` بەکاربهێنە بۆ گواستنەوەم بۆ کەناڵەکەت.",
"notInVoice": "من لە کەناڵێکی دەنگیدا نییم.", "notInVoice": "من لە کەناڵێکی دەنگیدا نییم.",
"queueEmpty": "📭 ڕیزبەندییەکە بەتاڵە. `{{prefix}}play` بەکاربهێنە بۆ زیادکردنی گۆرانی!", "queueEmpty": "📭 ڕیزبەندییەکە بەتاڵە. `{{prefix}}play` بەکاربهێنە بۆ زیادکردنی گۆرانی!",
"queueEnded": "🎵 ڕیزبەندییەکە تەواو بوو — هیچ شتێک نەماوە بۆ پەخشکردن. گۆرانی زیاتر زیاد بکە بە `{{prefix}}play`!", "queueEnded": "🎵 ڕیزبەندییەکە تەواو بوو — هیچ شتێک نەماوە بۆ پەخشکردن. گۆرانی زیاتر زیاد بکە بە `{{prefix}}play`!",
+2
View File
@@ -202,6 +202,8 @@
"noVoiceChannel": "⚠️ Bitte trete zuerst einem Sprachkanal bei.", "noVoiceChannel": "⚠️ Bitte trete zuerst einem Sprachkanal bei.",
"noVoiceStrict": "⚠️ Du musst einem Sprachkanal beitreten, um diesen Befehl zu nutzen.", "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.", "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.",
"notInVoice": "Ich bin in keinem Sprachkanal.", "notInVoice": "Ich bin in keinem Sprachkanal.",
"queueEmpty": "📭 Die Warteschlange ist leer. Nutze `{{prefix}}play`, um Songs hinzuzufügen!", "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!", "queueEnded": "🎵 Die Warteschlange ist zu Ende — nichts mehr abzuspielen. Füge weitere Songs mit `{{prefix}}play` hinzu!",
+2
View File
@@ -202,6 +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.", "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.", "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.", "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.",
"notInVoice": "I'm not in a voice channel.", "notInVoice": "I'm not in a voice channel.",
"queueEmpty": "📭 The queue is empty. Use `{{prefix}}play` to add songs!", "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`!", "queueEnded": "🎵 The queue has ended — nothing left to play. Add more songs with `{{prefix}}play`!",
+2
View File
@@ -202,6 +202,8 @@
"noVoiceChannel": "⚠️ Por favor, entre em um canal de voz primeiro.", "noVoiceChannel": "⚠️ Por favor, entre em um canal de voz primeiro.",
"noVoiceStrict": "⚠️ Você precisa entrar em um canal de voz para usar este comando.", "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.", "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.",
"notInVoice": "Não estou em um canal de voz.", "notInVoice": "Não estou em um canal de voz.",
"queueEmpty": "📭 A fila está vazia. Use `{{prefix}}play` para adicionar músicas!", "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`!", "queueEnded": "🎵 A fila acabou — nada mais para tocar. Adicione mais músicas com `{{prefix}}play`!",
+2
View File
@@ -202,6 +202,8 @@
"noVoiceChannel": "⚠️ Lütfen önce bir ses kanalına katılın.", "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.", "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.", "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.",
"notInVoice": "Bir ses kanalında değilim.", "notInVoice": "Bir ses kanalında değilim.",
"queueEmpty": "📭 Kuyruk boş. Şarkı eklemek için `{{prefix}}play` kullanın!", "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!", "queueEnded": "🎵 Kuyruk bitti — çalacak bir şey kalmadı. Daha fazla şarkı eklemek için `{{prefix}}play` kullanın!",