Skip to content

Commit

Permalink
feat(commands): add help command
Browse files Browse the repository at this point in the history
Introduces command documentation. Can display all the available commands or detailed way of using a specific command
  • Loading branch information
dankerow committed Jun 3, 2024
1 parent 1fc48a6 commit 260203c
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/commands/miscellaneous/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { CommandContext } from '@/types'
import type { Blop } from '@/structures'
import type { APIEmbed } from 'discord.js'

import { Command } from '@/structures'

export default class Help extends Command {
constructor(client: Blop) {
super(client, {
_filename: import.meta.url,
name: 'help',
description: () => 'Displays all the available commands.',
options: [
{
name: 'command',
description: 'Display information about a specific command',
type: 3
}
]
})
}

execute({ client, interaction }: CommandContext) {
const commandArg = interaction.options.getString('command')
if (commandArg) {
const command = client.commands.find((module) => module.name === commandArg.toLowerCase())

if (!command) return 'Command not found.'

return {
embeds: [
{
author: {
name: `Command Documentation: ${command.name}`,
icon_url: client.user.displayAvatarURL()
},
color: 7154431,
description: command.description({ client })
}
]
}
}

const embed: APIEmbed = {
author: {
name: `${client.user.username} Documentation`,
icon_url: client.user.displayAvatarURL()
},
color: 7154431,
description: 'To get more details about how to use commands, do `/help <command>`.',
fields: [],
footer: {
text: '<> means required command parameter | [] means optional command parameter'
}
}

const categories: string[] = []

client.commands.forEach((command) => {
if (!categories.includes(command.category)) {
categories.push(command.category)
}
})

categories.forEach((category) => {
const commands = client.commands.filter((module) => module.category === category)
if (commands.length < 1) return

embed.fields!.push({
name: category,
value: `\`${commands.map((command) => command.name).join('`, `')}\``
})
})

return { embeds: [embed] }
}
}

0 comments on commit 260203c

Please sign in to comment.