diff --git a/src/commands/voice/userListener.ts b/src/commands/voice/userListener.ts new file mode 100644 index 0000000..7ba7215 --- /dev/null +++ b/src/commands/voice/userListener.ts @@ -0,0 +1,28 @@ +import { VoiceState } from "discord.js"; +import { Command } from "../../commands"; +import { getVoiceConnection } from "@discordjs/voice"; + +const cmd: Command = { + voiceStateListener: async function (oldState: VoiceState): Promise { + const guild = oldState.guild; + if (!guild) return; + + const voiceConnection = getVoiceConnection(guild.id); + if (!voiceConnection) return; + + const me = guild.members.me; + if (!me) + return; + + if (!me.voice.channel) + return; + + if (me.voice.channel.members.size > 1) + return; + + voiceConnection.disconnect(); + voiceConnection.destroy(); + } +} + +export default cmd; \ No newline at end of file