Main Code

mail@pastecode.io avatar
unknown
javascript
a year ago
1.5 kB
2
Indexable
Never
// SRC/INDEX.JS
require("dotenv").config({ path: ".env" });
const fs = require("fs");
const { Client, GatewayIntentBits, Collection } = require("discord.js");
const { token } = process.env;

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();
client.commandArray = [];
client.modals = new Collection();

const functionFolders = fs.readdirSync("./src/functions");
for (const folder of functionFolders) {
  const functionFiles = fs
    .readdirSync(`./src/functions/${folder}`)
    .filter((file) => file.endsWith(".js"));
  for (const file of functionFiles)
    require(`./functions/${folder}/${file}`)(client);
}

client.handleComponents();
client.handleCommands();
client.handleEvents();
client.login(token);

// SRC/FUNCTIONS/HANDLERS/handleCommands.js
const fs = require("node:fs");

module.exports = (client) => {
  client.handleCommands = async () => {
    const commandFolders = fs.readdirSync("./src/commands");
    for (const folder of commandFolders) {
      const commandFiles = fs
        .readdirSync(`./src/commands/${folder}`)
        .filter((file) => file.endsWith(".js"));

      const { commands, commandArray } = client;

      for (const file of commandFiles) {
        const command = require(`../../commands/${folder}/${file}`);
        commands.set(command.data.name, command);
        commandArray.push(command.data.toJSON());
        console.log(`✅ Comando: ${command.data.name} registrado com sucesso!`);
      }
    }
  };
};