fix(lavalink): Update leave for Shoukaku integration

This commit is contained in:
Jose Daniel G. Percy 2025-04-24 01:21:44 +08:00
parent 0d0125bf55
commit a54becb3a0

View File

@ -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}.`);