thaldrin/DiscordModules/General/help.js

127 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-11-10 08:42:09 +00:00
const Command = require('../../src/structures/Command');
const { MessageEmbed } = require('discord.js');
2019-10-14 11:19:41 +00:00
module.exports = class Help extends Command {
2019-11-10 08:42:09 +00:00
constructor() {
super({
name: 'help',
description: 'View a list of available commands or information on a specific command.',
aliases: [ 'h' ],
module: 'General',
cooldown: 0,
guildOnly: false,
developerOnly: false
});
}
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
async command(ctx) {
if (!ctx.args.length) {
const commands = [
[
'General',
ctx.client.commands
.filter((command) => command.module == 'General')
.map((command) => `${command.name}`)
.join(' | ')
],
/* [
'Images',
ctx.client.commands
.filter((command) => command.module == 'Images')
.map((command) => `${command.name}`)
.join(' | ')
], */
[
'Images',
ctx.client.commands
.filter((command) => command.module == 'Images')
.map((command) => `${command.name}`)
.join(' | ')
],
[
'Roleplay',
ctx.client.commands
.filter((command) => command.module == 'Roleplay')
.map((command) => `${command.name}`)
.join(' | ')
],
[
'Settings',
ctx.client.commands
.filter((command) => command.module == 'Settings')
.map((command) => `${command.name}`)
.join(' | ')
]
];
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
if (ctx.isDeveloper)
commands.push([
'Developers',
ctx.client.commands
.filter((command) => command.module == 'Developers')
.map((command) => `${command.name}`)
.join(' | ')
]);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
return ctx.send({
embed: {
description: `Use \`'help command\` to get help on a specific command`,
fields: commands.map((group) => {
return new Object({
name: group[0],
value: group[1]
});
}),
color: 0xff873f
}
});
} else {
const command = ctx.client.commands.find(
(c) =>
c.name == ctx.args[0].toLowerCase() || (c.aliases && c.aliases.includes(ctx.args[0].toLowerCase()))
);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
let fields = [
{
name: 'Module',
value: command.module,
inline: true
},
{
name: 'Aliases',
value: command.aliases.length == 0 ? 'No aliases' : command.aliases.join(', '),
inline: true
},
{
name: 'Cooldown',
value: command.cooldown == 0 ? 'No cooldown' : `${command.cooldown}s`,
inline: true
},
{
name: 'Server only?',
value: command.guildOnly ? 'Yes' : 'No',
inline: true
},
{
name: 'Developers only?',
value: command.developerOnly ? 'Yes' : 'No',
inline: true
}
];
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
if (!command)
return ctx.send(`That command couldn't be found. See the \`help\` command for valid commands.`);
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
let embed = new MessageEmbed()
.setTitle(command.name)
.setDescription(command.description)
.setColor(0xff873f);
fields.forEach((i) => {
embed.addField(i.name, i.value, i.inline);
});
2019-10-14 11:19:41 +00:00
2019-11-10 08:42:09 +00:00
return ctx.send(embed);
}
}
2019-10-14 11:19:41 +00:00
};