A
This commit is contained in:
parent
daf79b8403
commit
cf7098a94b
|
@ -23,7 +23,13 @@ class Bot {
|
|||
|
||||
// THIS IS IMPORTANT: Make sure CommandManager is initialized AFTER the client
|
||||
// and before using it anywhere else
|
||||
try {
|
||||
this.commandManager = new CommandManager(this.client);
|
||||
console.log("Command Manager initialized successfully");
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize Command Manager:", error);
|
||||
this.commandManager = null; // Set to null instead of leaving undefined
|
||||
}
|
||||
|
||||
// Authorized users for commands - Parse comma-separated list from env variable
|
||||
this.authorizedUserIds = process.env.AUTHORIZED_USER_IDS
|
||||
|
@ -73,7 +79,12 @@ class Bot {
|
|||
|
||||
// Add safety check before trying to register commands
|
||||
if (this.commandManager && typeof this.commandManager.registerGlobalCommands === 'function') {
|
||||
try {
|
||||
await this.commandManager.registerGlobalCommands();
|
||||
console.log("Global commands registered successfully");
|
||||
} catch (error) {
|
||||
console.error("Error registering global commands:", error);
|
||||
}
|
||||
} else {
|
||||
console.error('Command manager not properly initialized - cannot register commands');
|
||||
}
|
||||
|
@ -165,7 +176,7 @@ class Bot {
|
|||
fields: [
|
||||
{
|
||||
name: "Bot Name",
|
||||
value: this.client.user.tag,
|
||||
value: this.client?.user?.tag || "Unknown (Client unavailable)",
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
|
@ -192,11 +203,8 @@ class Bot {
|
|||
});
|
||||
}
|
||||
|
||||
// Stop notification service if running
|
||||
if (this.notificationService?.isRunning) {
|
||||
this.notificationService.stop();
|
||||
}
|
||||
|
||||
// Only attempt to send notifications if client is ready
|
||||
if (this.client?.isReady()) {
|
||||
// Notify all recipients
|
||||
for (const userId of this.notificationRecipientIds) {
|
||||
try {
|
||||
|
@ -217,6 +225,9 @@ class Bot {
|
|||
console.error("Failed to send shutdown notification to status channel:", error.message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("Client not ready, cannot send shutdown notifications");
|
||||
}
|
||||
}
|
||||
|
||||
async start() {
|
||||
|
|
27
index.js
27
index.js
|
@ -51,8 +51,31 @@ async function shutdown(signal) {
|
|||
}
|
||||
|
||||
// Register shutdown handlers
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Received SIGINT. Shutting down gracefully...');
|
||||
try {
|
||||
// If you have the bot instance available, call shutdown method
|
||||
if (global.discordBot) {
|
||||
await global.discordBot.sendShutdownNotification("SIGINT received");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error shutting down Discord bot:", error);
|
||||
}
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('Received SIGTERM. Shutting down gracefully...');
|
||||
try {
|
||||
// If you have the bot instance available, call shutdown method
|
||||
if (global.discordBot) {
|
||||
await global.discordBot.sendShutdownNotification("SIGTERM received");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error shutting down Discord bot:", error);
|
||||
}
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Catch uncaught exceptions
|
||||
process.on('uncaughtException', (error) => {
|
||||
|
|
Loading…
Reference in a new issue