Created
January 10, 2021 05:20
-
-
Save limxuan/bbc58a0fa4aa6dce2caefc4d43e7486a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = require('../../src/index') | |
const prefix = client.prefix; | |
const { Collection } = require('discord.js'); | |
const Timeout = new Collection(); | |
const ms = require('ms') | |
client.on('message', async message =>{ | |
if(message.author.bot) return; | |
if(!message.content.startsWith(prefix)) return; | |
if(!message.guild) return; | |
const args = message.content.slice(prefix.length).trim().split(/ +/g); | |
const cmd = args.shift().toLowerCase(); | |
if(cmd.length == 0 ) return; | |
let command = client.commands.get(cmd) | |
if(!command) command = client.commands.get(client.aliases.get(cmd)); | |
if (command) { | |
if(command.cooldown) { | |
if(Timeout.has(`${command.name}${message.author.id}`)) return message.channel.send(`You are on a \`${ms(Timeout.get(`${command.name}${message.author.id}`) - Date.now(), {long : true})}\` cooldown.`) | |
command.run(client, message, args) | |
Timeout.set(`${command.name}${message.author.id}`, Date.now() + command.cooldown) | |
setTimeout(() => { | |
Timeout.delete(`${command.name}${message.author.id}`) | |
}, command.cooldown) | |
} else command.run(client, message, args); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
M