main.js: const Discord = require('discord.js'); const message = require('./events/guild/message'); require('dotenv').config(); const client = new Discord.Client({intents: [Discord.Intents.FLAGS.GUILDS,Discord.Intents.FLAGS.GUILD_MESSAGES, "GUILD_VOICE_STATES"], partials: ["MESSAGE", "CHANNEL", "REACTION"]}); client.commands = new Discord.Collection(); client.event = new Discord.Collection(); require("./functions/event_handler")(client); require("./functions/command_handler")(client); console.log(message) client.login(process.env.TOKEN); messageCreate.js: const { Client, Message, MessageEmbed } = require("discord.js"); const { Collection } = require("mongoose"); const Dotenv = require("dotenv"); Dotenv.config(); module.exports = { name: "messageCreate", /** * * @param {Client} client * @param {Message} message */ async execute(client, message, Discord) { if(!message.content.startsWith(process.env.PREFIX) || message.author.bot) return; const args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/); const commandName = args.Shift().toLowerCase(); const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); console.log(message) if(!command) return; if (command.permissions) { const authorPerms = message.channel.permisssionsFor(message.author); if(!authorPerms || !authorPerms.has(command.permissions)) { const noPerms = new MessageEmbed() .setColor('RED') .setDiscription('u do not have the required permissions to run this command!'); message.reply({embeds: [noPerms]}) .then((sent) => { setTimeout(() => { sent.delete(); }, 7000) }) } } const { cooldowns } = client; if(!cooldowns.has(command.name)) { cooldowns.set(command.name, new Collection()); } const now = Date.now(); const timestamps = cooldowns.get(command.name); const cooldownAmount = (command.cooldown || 1)* 1000; if(timestamps.has(message.author.id)) { const expirationTime = timestamps.get(message.author.id) + cooldownAmount; if (now < expirationTime) { const timeleft = (expirationTime - now) / 1000; const timeleftEmbed = new MessageEmbed() .setColor('RED') .setDescription(`pls wait another ${timeleft.toFixed(1)} more secondss to run this command again!`) return message.channel.send({emdebs: [timeleftEmbed]}) .then((err) => { setTimeout(() => { sent.delete(); }, 7000); }); }; }; timestamps.set(message.author.id, now); setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); try { command.execute(message, args, commandName, client, Discord); } catch (error) { console.log(error); const ErrorEmbed = new MessageEmbed() .setColor('RED') .setDiscription(`an error happened while trying to execute this code!`) message.channel.send({embeds: [ErrorEmbed]}); }; } }