DiscordTickets/commands/help.js

109 lines
4.8 KiB
JavaScript
Raw Normal View History

2019-05-04 01:42:29 +03:00
const Discord = require('discord.js');
2019-05-04 01:54:28 +03:00
const { version } = require('../package.json');
2019-05-04 02:01:33 +03:00
const config = require('../config.json');
2019-05-06 19:18:43 +03:00
const log = require(`leekslazylogger`);
2019-05-04 00:09:48 +03:00
module.exports = {
2019-05-04 01:54:28 +03:00
name: 'help',
description: 'Displays help menu',
usage: '[command]',
aliases: ['command', 'commands'],
2020-08-03 18:39:39 +03:00
example: 'help new',
2019-05-04 01:54:28 +03:00
args: false,
2019-05-04 02:01:33 +03:00
cooldown: config.cooldown,
2020-08-03 18:39:39 +03:00
guildOnly: true,
2019-05-04 02:01:33 +03:00
execute(message, args) {
2019-05-04 00:09:48 +03:00
// command starts here
message.delete();
2020-08-03 18:39:39 +03:00
const data = [];
const { commands } = message.client;
2019-05-04 16:29:49 +03:00
2019-05-04 01:54:28 +03:00
if (config.useEmbeds) {
2019-05-04 16:29:49 +03:00
if (!args.length) {
data.push('__**Commands**__');
data.push(commands.map(command => `**${config.prefix}${command.name}** : \`${command.description}\``).join('\n'));
2019-09-09 20:16:50 +03:00
data.push(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`);
2019-05-04 16:29:49 +03:00
const embed = new Discord.RichEmbed()
2020-08-03 18:39:39 +03:00
.setTitle("Commands")
.setColor(config.colour)
.setDescription(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`)
// .addField("...", `...`, true)
// .addField("...", `...`, true)
.setFooter(`DiscordTickets by Eartharoid`);
let cmds = [];
cmds.push(commands.map(command => embed.addField(`${config.prefix}${command.name}`, `\`${command.description}\``)));
message.channel.send(embed)
2019-05-04 16:29:49 +03:00
.then(() => {
if (message.channel.type === 'dm') return;
// message.channel.send(`A list of commands has been sent to you.`);
})
.catch(error => {
// console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
2019-05-05 16:31:21 +03:00
log.warn(`Could not DM help menu to ${message.author.tag}, sending to server channel instead`);
2019-05-04 16:29:49 +03:00
message.channel.send(`:x: **Sorry!** There was an error whilst sending the help menu via DMs.`)
message.channel.send(data, { split: true })
});
} else {
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
if (!command) {
const notCmd = new Discord.RichEmbed()
2020-08-03 18:39:39 +03:00
.setColor("#E74C3C")
.setDescription(`:x: **Invalid command name** (\`${config.prefix}help\`)`);
return message.channel.send(notCmd);
2019-05-04 16:29:49 +03:00
}
const cmd = new Discord.RichEmbed()
2020-08-03 18:39:39 +03:00
.setColor(config.colour)
.addField(`Command`,`\`${command.name}\``, true)
.setFooter(`DiscordTickets by Eartharoid`);
2019-05-04 16:29:49 +03:00
if (command.aliases) cmd.addField("Aliases", `\`${command.aliases.join(', ')}\``, true);
if (command.description) cmd.addField("Description", `\`${command.description}\``, false);
if (command.usage) cmd.addField("Usage", `\`${config.prefix}${command.name} ${command.usage}\``, false)
if (command.example) cmd.addField("Example", `\`${config.prefix}${command.example}\``, false);
2020-08-03 18:39:39 +03:00
message.channel.send(cmd);
2019-05-04 16:29:49 +03:00
}
2019-05-04 00:09:48 +03:00
} else {
2019-05-04 16:29:49 +03:00
// message.channel.send(`**Prefix =** \`${config.prefix}\`\n**Bot Version =** \`${version}\``)
if (!args.length) {
data.push('__**Commands**__');
data.push(commands.map(command => `**${config.prefix}${command.name}** : \`${command.description}\``).join('\n'));
2019-09-09 20:16:50 +03:00
data.push(`\nType \`${config.prefix}help [command]\` for more information about a specific command.`);
2019-05-04 16:29:49 +03:00
return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return;
// message.channel.send(`A list of commands has been sent to you.`);
})
.catch(error => {
// console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
2019-05-05 16:31:21 +03:00
log.warn(`Could not DM help menu to ${message.author.tag}, sending to server channel instead`);
2019-05-04 16:29:49 +03:00
message.channel.send(`:x: **Sorry!** There was an error whilst sending the help menu via DMs.`)
message.channel.send(data, { split: true })
});
}
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
2020-08-03 18:39:39 +03:00
if (!command) return message.reply(':x: **Invalid command**');
2019-05-04 16:29:49 +03:00
data.push(`**Command:** \`${command.name}\``);
if (command.aliases) data.push(`**Aliases:** \`${command.aliases.join(', ')}\``);
if (command.description) data.push(`**Description:** \`${command.description}\``);
if (command.usage) data.push(`**Usage:** \`${config.prefix}${command.name} ${command.usage}\``);
if (command.example) data.push(`**Example:** \`${command.example}\``);
data.push(`**Cooldown:** \`${command.cooldown || 3} second(s)\``);
2020-08-03 18:39:39 +03:00
message.channel.send(data, { split: true });
2019-05-04 00:09:48 +03:00
}
// command ends here
2019-05-04 01:54:28 +03:00
},
2019-05-04 00:09:48 +03:00
};