From b19e6fb95c52519d881a56b5104662447077354e Mon Sep 17 00:00:00 2001 From: Myx Date: Thu, 29 Jun 2023 04:00:50 +0200 Subject: [PATCH] Leave on alone --- .vscode/settings.json | 5 ++++- index.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4aa884e..1094061 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,10 @@ "editor.codeActionsOnSave": { "source.fixAll": true }, - "eslint.validate": ["javascript"] + "eslint.validate": [ + "javascript" + ], + "files.eol": "\n" // "editor.formatOnSave": true, // "eslint.format.enable": true diff --git a/index.js b/index.js index 6bcee7d..65ee56c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const { Client, GatewayIntentBits } = require('discord.js'); const process = require('dotenv').config(); +const { getVoiceConnection } = require('@discordjs/voice'); const { registerCommands } = require('./utils/registerCommands'); const { playCommand } = require('./commands/play'); const { queueCommand } = require('./commands/queue'); @@ -27,6 +28,17 @@ client.on('ready', async () => { await registerCommands(clientId, token); }); +client.on('voiceStateUpdate', (oldState) => { + const voiceChannel = oldState.channel; + if (voiceChannel && voiceChannel.members.size === 1) { + const connection = getVoiceConnection(voiceChannel.guild.id); + if (connection) { + connection.disconnect(); + connection.destroy(); + } + } +}); + client.on('interactionCreate', async (interaction) => { if (!interaction.isCommand()) return; @@ -53,4 +65,4 @@ client.on('messageCreate', async (message) => { } }); -client.login(token); +client.login(token); \ No newline at end of file