const { Client, Intents, Collection } = require('discord.js') const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES ] }) require('dotenv').config(); const fs = require('fs') const prefix = "+"; client.commands = new Collection() client.aliases = new Collection() const Timeout = new Collection() const commandFolders = fs.readdirSync('./commands'); const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js')); for(const folder of commandFolders) { const CommandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js')); for(const file of CommandFiles) { const command = require(`./commands/${folder}/${file}`); client.commands.set(command.name, command) command.aliases.forEach(alias => { client.aliases.set(alias, command.name) }) } } for(const file of eventFiles) { const event = require(`./events/${file}`) if(event.once) { client.once(event.name, (...args) => event.execute(...args)) } else { client.on(event.name, (...args) => event.execute(...args)) } } client.on('messageCreate', async (message) => { if(!message.content.toLowerCase().startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).trim().split(/\s+/); const command = args.shift().toLowerCase(); if(!client.commands.has(command) && !client.aliases.has(command)) return; try{ const cmd = client.commands.get(command) || client.commands.find(a => a.aliases && a.aliases.includes(command)) // This is where you now execute all your works with commands and aliases if (cmd) { const CD = require('./Schema/cooldownSchema') const cd = await CD.findOne({ Guild: message.guild.id, CommandName: command.name, UsedBy: message.author.id }); if (!cd || cd && Math.ceil((cd.Used + (cd.Cooldown * 1000) - Date.now())) <= 0) { if (cd) cd.deleteOne().catch(err => console.log(err)); if(cmd) cmd.execute(client, message, args) const cooldown = new CD({ guildID: message.guild.id, CommandName: command.name, Used: Date.now(), memberID: message.author.id, Cooldown: command.cooldown, }) cooldown.save().catch(err => console.log(err)); setTimeout(async () => { if (cd) cooldown.deleteOne().catch(err => console.log(err)); }, command.cooldown * 1000); } else if (cd && Math.ceil((cd.Used + (cd.Cooldown * 1000) - Date.now())) >= 1) { return message.reply(`You need to wait **${Math.ceil((cd.Used + (cd.Cooldown * 1000) - Date.now()) / 1000)}** seconds before using this command again!`).then(message.delete(2000)) } else { if(cmd) cmd.execute(client, message, args) } } } catch(err) { console.log(err) } }); const discordModals = require('discord-modals'); discordModals(client); client.login(process.env.token)