Compare commits
3 Commits
0d0125bf55
...
74cac2bfbb
| Author | SHA1 | Date | |
|---|---|---|---|
| 74cac2bfbb | |||
| bb7a796cf9 | |||
| a54becb3a0 |
@ -11,6 +11,13 @@ services:
|
|||||||
- LAVALINK_SERVER_PASSWORD=${LAVALINK_PASSWORD}
|
- LAVALINK_SERVER_PASSWORD=${LAVALINK_PASSWORD}
|
||||||
volumes:
|
volumes:
|
||||||
- ./application.yml:/opt/Lavalink/application.yml:ro,Z
|
- ./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:
|
bot:
|
||||||
build: .
|
build: .
|
||||||
@ -24,8 +31,10 @@ services:
|
|||||||
- LAVALINK_HOST=lavalink
|
- LAVALINK_HOST=lavalink
|
||||||
- LAVALINK_PORT=2333
|
- LAVALINK_PORT=2333
|
||||||
- LAVALINK_PASSWORD=${LAVALINK_PASSWORD}
|
- LAVALINK_PASSWORD=${LAVALINK_PASSWORD}
|
||||||
|
# Update depends_on to wait for healthcheck
|
||||||
depends_on:
|
depends_on:
|
||||||
- lavalink
|
lavalink:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
bot-network:
|
bot-network:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder, MessageFlags } = require('discord.js'); // Import MessageFlags
|
||||||
const logger = require('../utils/logger');
|
const logger = require('../utils/logger');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -6,11 +6,20 @@ module.exports = {
|
|||||||
.setName('leave')
|
.setName('leave')
|
||||||
.setDescription('Leaves the current voice channel'),
|
.setDescription('Leaves the current voice channel'),
|
||||||
async execute(interaction, client) { // Added client parameter
|
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) {
|
if (!player || !player.voiceChannel) {
|
||||||
return interaction.editReply('I am not currently in a voice channel!');
|
return interaction.editReply('I am not currently in a voice channel!');
|
||||||
}
|
}
|
||||||
@ -22,11 +31,11 @@ module.exports = {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const channelId = player.voiceChannel;
|
const channelId = player.voiceChannel; // Get channel ID from Shoukaku player
|
||||||
const channel = client.channels.cache.get(channelId);
|
const channel = client.channels.cache.get(channelId);
|
||||||
const channelName = channel ? channel.name : `ID: ${channelId}`; // Get channel name if possible
|
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}`);
|
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}.`);
|
await interaction.editReply(`Left ${channelName}.`);
|
||||||
|
|
||||||
|
|||||||
@ -212,19 +212,22 @@ class MusicPlayer {
|
|||||||
if (!node) throw new Error('No available Lavalink nodes!');
|
if (!node) throw new Error('No available Lavalink nodes!');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine search type
|
// Determine search type and prepare the identifier string
|
||||||
let searchOptions = {};
|
let identifier;
|
||||||
if (query.startsWith('http')) {
|
if (query.startsWith('http')) {
|
||||||
// Direct URL
|
// Direct URL
|
||||||
searchOptions = { query };
|
identifier = query;
|
||||||
} else {
|
} else {
|
||||||
// Search with prefix
|
// Search with prefix (Lavalink handles ytsearch/ytmsearch automatically with the plugin)
|
||||||
searchOptions = { query: `ytsearch:${query}` };
|
// identifier = `ytsearch:${query}`; // Prefix might not be needed with the plugin, let Lavalink decide
|
||||||
|
identifier = query; // Pass the raw query for non-URLs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the search
|
// Perform the search using the identifier string
|
||||||
const result = await node.rest.resolve(searchOptions);
|
const result = await node.rest.resolve(identifier);
|
||||||
if (!result || result.loadType === 'error' || result.loadType === 'empty') {
|
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');
|
throw new Error(result?.exception?.message || 'No results found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user