From a54becb3a0ba43dbbcc79324e9c106924f4ae6a8 Mon Sep 17 00:00:00 2001 From: aki Date: Thu, 24 Apr 2025 01:21:44 +0800 Subject: [PATCH] fix(lavalink): Update leave for Shoukaku integration --- src/commands/leave.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/commands/leave.js b/src/commands/leave.js index e115b01..897296b 100644 --- a/src/commands/leave.js +++ b/src/commands/leave.js @@ -1,4 +1,4 @@ -const { SlashCommandBuilder } = require('discord.js'); +const { SlashCommandBuilder, MessageFlags } = require('discord.js'); // Import MessageFlags const logger = require('../utils/logger'); module.exports = { @@ -6,11 +6,20 @@ module.exports = { .setName('leave') .setDescription('Leaves the current voice channel'), async execute(interaction, client) { // Added client parameter - await interaction.deferReply({ ephemeral: true }); + // Use flags for ephemeral deferral + await interaction.deferReply({ flags: MessageFlags.Ephemeral }); - const player = client.manager.get(interaction.guildId); + // Get the Shoukaku player manager + const musicPlayer = interaction.client.player; + if (!musicPlayer) { + logger.error('Music player not initialized on client object!'); + return interaction.editReply('The music player is not ready yet.'); + } - // Check if the player exists and the bot is in a voice channel + // Get the player for this guild using Shoukaku manager + const player = musicPlayer.getPlayer(interaction.guildId); + + // Check if the player exists (Shoukaku player object has voiceChannel property) if (!player || !player.voiceChannel) { return interaction.editReply('I am not currently in a voice channel!'); } @@ -22,11 +31,11 @@ module.exports = { // } try { - const channelId = player.voiceChannel; + const channelId = player.voiceChannel; // Get channel ID from Shoukaku player const channel = client.channels.cache.get(channelId); const channelName = channel ? channel.name : `ID: ${channelId}`; // Get channel name if possible - player.destroy(); // Disconnects, clears queue, and destroys the player instance + player.destroy(); // Use Shoukaku player's destroy method logger.info(`Player destroyed and left voice channel ${channelName} in guild ${interaction.guild.name} (${interaction.guildId}) by user ${interaction.user.tag}`); await interaction.editReply(`Left ${channelName}.`);