Make the strategy to complete the plan // loadCommands.ts
import { XarV } from "../global";
import { readdirSync } from "fs";
import { join } from "path";
import { handleStart } from "./handler/onStart";
import { handleReply } from "./handler/onReply";
import { handleCallback } from "./handler/onCallback";
import { handleChat } from "./handler/onChat";
declare global {
  var XarV2: {
    onReply: Map<any, any>;
  };
}
if (!global.XarV2) {
  global.XarV2 = {
    onReply: new Map()
  };
}
export const loadCommands = (bot: any) => {
  const scriptsPath = join(import.meta.dir, "..", "..", "scripts", "cmds");
  const commandFiles = readdirSync(scriptsPath).filter(file => file.endsWith(".js"));
  for (const file of commandFiles) {
    const { XarV2: command } = require(join(scriptsPath, file));
    if (command && command.config) {
      if (command.onStart) {
        XarV.commands.set(command.config.name, command);
        command.config.aliases.forEach((alias: string) => XarV.aliases.set(alias, command.config.name));
        XarV.commandFilesPath.push({ filePath: join(scriptsPath, file), commandName: [command.config.name, ...command.config.aliases] });
      }
      if (command.onChat) {
        XarV.commands.set(command.config.name, command);
      }
    }
  }
  bot.on("message", async (msg: any) => {
    await handleChat(bot, msg);
    const messageText = msg.text ? msg.text.trim() : "";
    const prefix = bot.prefix || "/";
    const [cmdText, ...args] = messageText.split(/\s+/);
    let commandName = cmdText;
    let usePrefix = true;
    if (await handleReply(bot, msg)) {
      return;
    }
    if (cmdText.startsWith(prefix)) {
      commandName = cmdText.slice(prefix.length);
    } else {
      usePrefix = false;
    }
    const command = XarV.commands.get(commandName) || XarV.commands.get(XarV.aliases.get(commandName));
    if (!command) {
      if (usePrefix || messageText === prefix) {
        bot.sendMessage(msg.chat.id, `Command "${commandName}" not found.`);
      }
      return;
    }
    if (command.config.usePrefix !== false && !usePrefix) {
      bot.sendMessage(msg.chat.id, `Please use the correct prefix: ${prefix}${commandName}`);
      return;
    }
    await handleStart(bot, msg, commandName, args);
  });
  bot.on("photo", async (msg: any) => await handleChat(bot, msg));
  bot.on("video", async (msg: any) => await handleChat(bot, msg));
  bot.on("audio", async (msg: any) => await handleChat(bot, msg));
  bot.on("document", async (msg: any) => await handleChat(bot, msg));
  bot.on("sticker", async (msg: any) => await handleChat(bot, msg));
  bot.on("new_chat_members", async (msg: any) => await handleChat(bot, msg));
  bot.on("left_chat_member", async (msg: any) => await handleChat(bot, msg));
  bot.on("callback_query", async (callbackQuery: any) => {
    await handleCallback(bot, callbackQuery);
  });
}; 
add some function for loading cmds specific cmds or unloading cmds while bot is on its gonna be a hassle for manually add cmd and restarting bot to avoid it create cmd to load unload and install Files
create 
loadAll loadFiles unload installcmd function and cmd
also add one more thing
let errors = 0;
let loadedCommands = 0;
let loadedEvents = 0;
const failedCommands = [];
const failedEvents = [];
const commandNames = new Set();
const eventNames = new Set();
global.cmds = new Map();
global.events = new Map();
 loadEvents = (bot: any) => {
  const scriptsPath = join(import.meta.dir, "..", "..", "scripts", "events");
  const eventFiles = readdirSync(scriptsPath).filter(file => file.endsWith(".js"));
  
  
  this is for events