Files
discord-rpg-concept/src/events/ready.ts

38 lines
1.3 KiB
TypeScript

import { Events } from "discord.js";
import { schedulerService } from "@/modules/system/scheduler";
import type { Event } from "@lib/types";
const event: Event<Events.ClientReady> = {
name: Events.ClientReady,
once: true,
execute: async (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
schedulerService.start();
// Check for restart context
const { readFile, unlink } = await import("fs/promises");
const { createSuccessEmbed } = await import("@lib/embeds");
try {
const contextData = await readFile(".restart_context.json", "utf-8");
const context = JSON.parse(contextData);
// Validate context freshness (e.g., ignore if older than 5 minutes)
if (Date.now() - context.timestamp < 5 * 60 * 1000) {
const channel = await c.channels.fetch(context.channelId);
if (channel && channel.isSendable()) {
await channel.send({
embeds: [createSuccessEmbed("Bot is back online! Redeploy successful.", "System Online")]
});
}
}
await unlink(".restart_context.json");
} catch (error) {
// Ignore errors (file not found, etc.)
}
},
};
export default event;