-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandDispatch.js
More file actions
40 lines (34 loc) · 1.24 KB
/
commandDispatch.js
File metadata and controls
40 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module.exports =
{
handle(client, message, cooldowns)
{
// Ignore bot messages and messages that dont start with the prefix defined in the config file
if(!message.content.startsWith(client.botConfig.prefix) || message.author.bot) return;
// Split commands and arguments from message so they can be passed to functions
const args = message.content.slice(client.botConfig.prefix.length).split(/ +/);
const commandName = args.shift().toLowerCase();
// If the command isn't in the command folder, move on
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if(!command) return;
// If the command requires arguments, make sure they're there.
if (command.args && !args.length)
{
let reply = 'That command requires more details!';
// If we have details on how to use the args, provide them
if (command.usage) {
reply += `\nThe proper usage would be: \`${client.botConfig.prefix}${command.name} ${command.usage}\``;
}
// Send a reply from the bot about any error encountered
return message.channel.send(reply);
}
try
{
// Run the command
command.execute(message, args);
}
catch(error)
{
console.error(error);
}
}
}