From 6b4603f1f780b45d4cb303713849b0208ec3e121 Mon Sep 17 00:00:00 2001 From: entar Date: Thu, 22 May 2025 20:53:22 +0700 Subject: [PATCH] Added music folder to gitignore and added stop and leave commands --- .gitignore | 3 ++- commands/voice.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 487dd04..125949f 100644 --- a/.gitignore +++ b/.gitignore @@ -131,4 +131,5 @@ dist .pnp.* -.env \ No newline at end of file +.env +music/ \ No newline at end of file diff --git a/commands/voice.js b/commands/voice.js index 4f7304f..1713a46 100644 --- a/commands/voice.js +++ b/commands/voice.js @@ -5,6 +5,8 @@ const YTDlpWrap = require("yt-dlp-wrap").default const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`) +const players = {} + module.exports = [ { name: "play", @@ -45,8 +47,6 @@ module.exports = [ connection = getVoiceConnection(ctx.guild.id) } - console.log(connection) - const metadata = await ytDlp.getVideoInfo(link); ctx.reply(`Playing ${metadata.title}`) @@ -61,7 +61,13 @@ module.exports = [ '--audio-format', 'mp3' ]).on('close', () => { + if (players[ctx.guild.id]) { + players[ctx.guild.id].stop() + } + const player = createAudioPlayer() + + players[ctx.guild.id] = player const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`) @@ -70,5 +76,32 @@ module.exports = [ connection.subscribe(player) }) } + }, + { + name: "stop", + description: "Stop music", + run: (ctx) => { + const voice = ctx.guild.members.me.voice + + if (!voice || !players[ctx.guild.id]) { + return ctx.reply("Not in a voice channel.") + } + + players[ctx.guild.id].stop() + } + }, + { + name: "leave", + description: "Leave the channel", + run: (ctx) => { + const voice = ctx.guild.members.me.voice + + if (!voice || !players[ctx.guild.id]) { + return ctx.reply("Not in a voice channel.") + } + players[ctx.guild.id].stop() + + voice.disconnect() + } } ] \ No newline at end of file