fix(docker): Update environment variables and improve connection handling for Lavalink
This commit is contained in:
@@ -5,11 +5,19 @@ const loadErelaEvents = require('../structures/ErelaEvents'); // Import the Erel
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
once: true, // This event should only run once
|
||||
execute(client) {
|
||||
async execute(client) {
|
||||
logger.info(`Ready! Logged in as ${client.user.tag}`);
|
||||
|
||||
// Wait a moment before initializing Erela.js to give Lavalink time to start up
|
||||
// This is especially important in Docker environments
|
||||
await new Promise(resolve => setTimeout(resolve, 5000)); // 5 second delay
|
||||
|
||||
// Initialize the Erela Manager once the client is ready
|
||||
try {
|
||||
// Log the actual connection details being used (without exposing the password)
|
||||
const node = client.manager.nodes[0];
|
||||
logger.info(`Attempting to connect to Lavalink at ${node.options.host}:${node.options.port} with identifier "${node.options.identifier}"`);
|
||||
|
||||
client.manager.init(client.user.id);
|
||||
logger.info(`Erela.js Manager initialized for user ID: ${client.user.id}`);
|
||||
|
||||
@@ -18,14 +26,19 @@ module.exports = {
|
||||
|
||||
} catch (error) {
|
||||
logger.error(`Failed to initialize Erela.js Manager: ${error.message}`);
|
||||
// Depending on requirements, you might want to exit or handle this differently
|
||||
// Try to reconnect after a delay if initialization fails
|
||||
setTimeout(() => {
|
||||
try {
|
||||
client.manager.init(client.user.id);
|
||||
logger.info(`Erela.js Manager initialization retry successful`);
|
||||
loadErelaEvents(client);
|
||||
} catch (retryError) {
|
||||
logger.error(`Retry initialization also failed: ${retryError.message}`);
|
||||
}
|
||||
}, 10000); // 10 second delay before retry
|
||||
}
|
||||
|
||||
// Placeholder for setting activity, etc.
|
||||
// client.user.setActivity('Music!', { type: 'LISTENING' });
|
||||
|
||||
// Note: Slash command registration is typically done in a separate deploy script,
|
||||
// not usually within the ready event for production bots.
|
||||
// We will create a deploy-commands.js script later.
|
||||
// Set activity status
|
||||
client.user.setActivity('Music | /play', { type: 'LISTENING' });
|
||||
},
|
||||
};
|
||||
|
||||
15
src/index.js
15
src/index.js
@@ -28,14 +28,16 @@ const client = new Client({
|
||||
});
|
||||
|
||||
// Initialize Erela.js Manager
|
||||
// We need the client to be ready before fully initializing the manager
|
||||
client.manager = new Manager({
|
||||
nodes: [
|
||||
{
|
||||
host: process.env.LAVALINK_HOST || 'localhost', // Default host if not set
|
||||
port: parseInt(process.env.LAVALINK_PORT || '2333'), // Default port if not set
|
||||
password: process.env.LAVALINK_PASSWORD || 'youshallnotpass', // Default password if not set
|
||||
secure: process.env.LAVALINK_SECURE === 'true', // Optional: Use true for wss://
|
||||
host: process.env.LAVALINK_HOST || 'localhost',
|
||||
port: parseInt(process.env.LAVALINK_PORT || '2333'),
|
||||
password: process.env.LAVALINK_PASSWORD || 'youshallnotpass',
|
||||
secure: process.env.LAVALINK_SECURE === 'true',
|
||||
retryAmount: 10, // Number of connection attempts
|
||||
retryDelay: 5000, // 5 seconds between each retry
|
||||
identifier: "lavalink", // Identifier for logs
|
||||
},
|
||||
],
|
||||
// Function to send raw voice data to Discord
|
||||
@@ -45,6 +47,9 @@ client.manager = new Manager({
|
||||
},
|
||||
});
|
||||
|
||||
// Show the actual Lavalink connection details (without exposing the actual password)
|
||||
logger.info(`Lavalink connection configured to: ${process.env.LAVALINK_HOST}:${process.env.LAVALINK_PORT} (Password: ${process.env.LAVALINK_PASSWORD ? '[SET]' : '[NOT SET]'})`);
|
||||
|
||||
// Collections for commands
|
||||
client.commands = new Collection();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user