const profileModel = require("../../models/profileSchema"); const { MessageEmbed } = require('discord.js') const cooldowns = new Map(); const db = require('../../models/warns'); const bonkData = require("../../models/bonkSchema"); module.exports = async (Discord, client, message) => { let profileData; try { profileData = await profileModel.findOne({ userID: message.author.id }); if(!profileData){ let profile = await profileModel.create({ userID: message.author.id, serverID: message.guild.id, coins: 1000, bank: 0, }); profile.save(); } } catch (err) { console.log(err); } let bonksters; try { bonksters = await profileModel.findOne({ userID: message.author.id }); if(!bonksters){ let profile = await profileModel.create({ userID: message.author.id, serverID: message.guild.id, bonks: 0 }); profile.save(); console.log(`database created for ${message.author.username}`) } } catch (err) { console.log(err); } const prefix = '-'; if(!message.content.startsWith(prefix) || message.author.bot) return; if(message.channel.type === "dm") { message.channel.send('This command is not available in DMs. Try it in a server') return; } const args = message.content.slice(prefix.length).split(/ +/); const cmd = args.shift().toLowerCase(); const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd)); if(!cooldowns.has(command.name)){ cooldowns.set(command.name, new Discord.Collection()); } const current_time = Date.now(); const time_stamps = cooldowns.get(command.name) const cooldown_amount = (command.cooldown) * 1000; if(time_stamps.has(message.author.id)){ const expiration_time = time_stamps.get(message.author.id) + cooldown_amount; if(current_time < expiration_time){ const time_left = (expiration_time - current_time) / 1000; const embed = new MessageEmbed() .setColor(`#c21000`) .setTitle(`---MESSAGE COOLDOWN---`) .setDescription(`Please wait ${time_left.toFixed(1)} more seconds before using ${command.name}`) return message.channel.send(embed) } } time_stamps.set(message.author.id, current_time) setTimeout(() => time_stamps.delete(message.author.id), cooldown_amount); try{ command.execute(client, message, args, cmd, Discord, profileData); } catch (err){ message.reply("Sorry, there was an error when trying to execute that command"); console.log(err); } }