UNPKG

create-discord-forge

Version:

A CLI made with Commander to create a Discord and easily add advanced features to your bot made with discord.js in TypeScript or JavaScript

38 lines (31 loc) 1.27 kB
const { Client, Collection, GatewayIntentBits } = require('discord.js'); const fs = require('fs'); const path = require('path'); const { token } = require('../config.json'); const InteractionCreate = require('./events/InteractionCreate'); const ClientReady = require('./events/ClientReady'); const client = new Client({ intents: GatewayIntentBits.Guilds }); client.commands = new Collection(); const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { const commandsPath = path.join(foldersPath, folder); const commandFiles = fs .readdirSync(commandsPath) .filter(file => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); // Set a new item in the Collection with the key as the command name and the value as the exported module if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log( `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`, ); } } } ClientReady(client); InteractionCreate(client); client.login(token);