Отключение бота от голосового канала
Не зная, как вы структурировали свои команды, трудно дать вам точный код. Все, что я могу вам сказать, это то, что я бы посмотрел, является ли бот голосовым каналом пользователя, и, если да, оставлю его, используя метод VoiceConnection.disconnect()
. Это будет выглядеть так:
// Assuming 'message' is the message with the command
let { channelID } = message.member.voice // Get the user's voice channel ID
if (channelID) {
// Find an existing connection to that channel
let connection = client.voice.connections.find(conn => conn.channel.id == channelID)
if (connection) // If you find one, use .disconnect()
connection.disconnect()
}
Создание таймера бездействия
Опять же, я не могу дать вам точный код, так как я не знаю, как вы настраиваете свой musi c бот. В этом суть: когда очередь заканчивается, вы можете создать таймер, используя setTimeout()
, если бот используется до окончания тайм-аута, вы можете отменить его, используя clearTimeout()
.
Вот как бы я это сделал:
// Somewhere so that it's in an accessible scope
let timeoutID;
// After the queue has ended
timeoutID = setTimeout(() => {
// This will run if the timeout reaches its end
// You can adapt the code above to disconnect from the voice channel
}, 15 * 60 * 1000) // You should use the time in ms
// If the bot is used again
clearTimeout(timeoutID)
timeoutID = undefined