Compare commits

..

No commits in common. "74cac2bfbbf3cfd7f64f7262e9537100f974c7f0" and "0d0125bf5594b393db05992a2e7ac9219148f660" have entirely different histories.

3 changed files with 15 additions and 36 deletions

View File

@ -11,13 +11,6 @@ services:
- LAVALINK_SERVER_PASSWORD=${LAVALINK_PASSWORD}
volumes:
- ./application.yml:/opt/Lavalink/application.yml:ro,Z
# Add healthcheck to verify Lavalink is ready
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:2333/v4/info"]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s # Give Lavalink time to start up initially
bot:
build: .
@ -31,10 +24,8 @@ services:
- LAVALINK_HOST=lavalink
- LAVALINK_PORT=2333
- LAVALINK_PASSWORD=${LAVALINK_PASSWORD}
# Update depends_on to wait for healthcheck
depends_on:
lavalink:
condition: service_healthy
- lavalink
networks:
bot-network:

View File

@ -1,4 +1,4 @@
const { SlashCommandBuilder, MessageFlags } = require('discord.js'); // Import MessageFlags
const { SlashCommandBuilder } = require('discord.js');
const logger = require('../utils/logger');
module.exports = {
@ -6,20 +6,11 @@ module.exports = {
.setName('leave')
.setDescription('Leaves the current voice channel'),
async execute(interaction, client) { // Added client parameter
// Use flags for ephemeral deferral
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
await interaction.deferReply({ ephemeral: true });
// 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.');
}
const player = client.manager.get(interaction.guildId);
// 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)
// Check if the player exists and the bot is in a voice channel
if (!player || !player.voiceChannel) {
return interaction.editReply('I am not currently in a voice channel!');
}
@ -31,11 +22,11 @@ module.exports = {
// }
try {
const channelId = player.voiceChannel; // Get channel ID from Shoukaku player
const channelId = player.voiceChannel;
const channel = client.channels.cache.get(channelId);
const channelName = channel ? channel.name : `ID: ${channelId}`; // Get channel name if possible
player.destroy(); // Use Shoukaku player's destroy method
player.destroy(); // Disconnects, clears queue, and destroys the player instance
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}.`);

View File

@ -212,22 +212,19 @@ class MusicPlayer {
if (!node) throw new Error('No available Lavalink nodes!');
try {
// Determine search type and prepare the identifier string
let identifier;
// Determine search type
let searchOptions = {};
if (query.startsWith('http')) {
// Direct URL
identifier = query;
searchOptions = { query };
} else {
// Search with prefix (Lavalink handles ytsearch/ytmsearch automatically with the plugin)
// identifier = `ytsearch:${query}`; // Prefix might not be needed with the plugin, let Lavalink decide
identifier = query; // Pass the raw query for non-URLs
// Search with prefix
searchOptions = { query: `ytsearch:${query}` };
}
// Perform the search using the identifier string
const result = await node.rest.resolve(identifier);
// Perform the search
const result = await node.rest.resolve(searchOptions);
if (!result || result.loadType === 'error' || result.loadType === 'empty') {
// Log the identifier for debugging if search fails
logger.debug(`Search failed for identifier: ${identifier}`);
throw new Error(result?.exception?.message || 'No results found');
}
@ -281,4 +278,4 @@ module.exports = {
return musicPlayer;
},
musicPlayer
};
};