import { Client, Collection, REST, Routes, Partials, GatewayIntentBits, } from "discord.js"; import Logger from "./structures/Logger.js"; import config from "./config.js"; import { loadCommands } from "./handlers/LoadCommands.js"; import { loadButtons } from "./handlers/LoadButtons.js"; import { loadModals } from "./handlers/LoadModals.js"; import { loadSelectMenus } from "./handlers/LoadSelectMenus.js"; import { loadEvents } from "./handlers/LoadEvents.js"; import { connect } from "mongoose"; const logger = new Logger(); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildMessagePolls, GatewayIntentBits.GuildWebhooks, GatewayIntentBits.AutoModerationExecution, GatewayIntentBits.GuildVoiceStates, ], partials: [ Partials.Message, // for message Partials.Channel, // for text channel Partials.GuildMember, // for guild member Partials.Reaction, // for message reaction ], }); client.commands = new Collection(); client.buttons = new Collection(); client.modals = new Collection(); client.selectMenus = new Collection(); async function registerCommands() { const rest = new REST({ version: "10" }).setToken(config.TOKEN); try { const commandsJSON = client.commands.map((cmd) => cmd.data.toJSON()); const data = await rest.put(Routes.applicationCommands(config.CLIENT_ID), { body: commandsJSON, }); logger.success(`Registered ${data.length} commands globally.`); } catch (err) { logger.error(`Failed to register commands: ${err.message}`); } } try { await loadCommands(client); await loadEvents(client); await loadButtons(client); await loadModals(client); await loadSelectMenus(client); await registerCommands(); await connect(config.URI); await client.login(config.TOKEN); } catch (error) { logger.error(error); }