-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandParser.js
More file actions
46 lines (44 loc) · 2.59 KB
/
commandParser.js
File metadata and controls
46 lines (44 loc) · 2.59 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
41
42
43
44
45
46
const config = require('./config.json')
module.exports = async (client, message) => {
const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js')
const dismisRow = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('dismiss')
.setLabel('Dismiss')
.setStyle('DANGER')
)
const commandErrorEmbed = new MessageEmbed()
.setColor('#0099ff')
.setDescription("The command to be executed was not found, Make sure you have entered the correct command name or give the suggestion below a try!\n\tSuggestion: \`[work in progress]\`")
.setFooter(message.author.username, message.author.avatarURL())
.setTimestamp()
if(message.author.bot) return undefined
const prefix = config.others.prefixes.find(p => message.content.startsWith(p))
if(!message.content.startsWith(prefix)) return undefined
const args = message.content.slice(prefix.length).trim().split(/ +/g)
const cmd = args.shift(prefix.length)?.toLowerCase()
if(!cmd) return undefined
const command = client.commands.get(cmd) ?? client.commands.find(c => c.data.name.replace(/-/g, "") === cmd.replace(/-/g, "") || (c.data.aliases && c.data.aliases.some(alias => alias.replace(/-/g, "") === cmd.replace(/-/g, ""))))
if(!command) return message.channel.send({
content: `**[Command not found]**: Command with name \`${client.functions.cutChars(cmd, 20)}\` not found.`,
embeds: [commandErrorEmbed],
components: [dismisRow]
})
const devOnlyErrorEmbed = new MessageEmbed()
.setColor('#FF005C')
.setDescription("This command is restricted to devlopers only.\n\nPermissions required: Developer[MISSING]")
.setFooter(message.author.username, message.author.avatarURL())
.setTimestamp()
if(command.data.devOnly === true) {
if(!config.others.devs.includes(message.author.id)) {
message.channel.send({
content: `**[Failed Executing Command]**: Failed executing command with name -> \`${command.data.name}\``,
embeds: [devOnlyErrorEmbed],
components: [dismisRow]
})
const trigger = false
if(trigger === false) return undefined
}
}
command.execute(client , message , args)
}