diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index ddd4b0f..6806d6f 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -9,6 +9,7 @@ import { import "../../modules/string"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; +import { goodDescription, goodName } from "../../utils/commands/help"; export default { scope: () => [], @@ -63,12 +64,16 @@ export default { // Add subcommands const all_commands: string[] = []; commands_name.forEach((command) => { - const json = client.commands.list.get(command)?.data.toJSON(); - all_commands.push(command); + const data = client.commands.list.get(command)?.data; + const name = goodName(data!, interaction.locale); + all_commands.push(name); - json?.options - ?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) - .forEach((subcommand) => all_commands.push(command + " " + subcommand.name)); + data + ?.toJSON() + .options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) + .forEach((subcommand) => + all_commands.push(name + " " + goodName(subcommand, interaction.locale)), + ); }); const commands = all_commands.reduce( @@ -111,12 +116,10 @@ export default { embeds: [ new EmbedBuilder() .setColor(Colors.Blurple) - .setTitle("`/" + command.data.name + "`") + .setTitle("`/" + goodName(command.data, interaction.locale) + "`") .setDescription( - // Loads the description - // according to the user's locals - command.data.description_localizations?.[interaction.locale] ?? - command.data.description, + // Loads the description according to the user's locals + goodDescription(command.data, interaction.locale), ), ], }); diff --git a/src/utils/commands/help.ts b/src/utils/commands/help.ts new file mode 100644 index 0000000..2ff72c9 --- /dev/null +++ b/src/utils/commands/help.ts @@ -0,0 +1,23 @@ +import { APIApplicationCommandSubcommandOption, Locale, SlashCommandBuilder } from "discord.js"; + +/** + * Find the name of the command, trying to get the correct locale + * @param data Command data + * @param locale Locale wanted + * @returns Command's name + */ +export const goodName = ( + data: SlashCommandBuilder | APIApplicationCommandSubcommandOption, + locale: Locale, +) => data.name_localizations?.[locale] ?? data.name; + +/** + * Find the description of the command, trying to get the correct locale + * @param data Command data + * @param locale Locale wanted + * @returns Command's description + */ +export const goodDescription = ( + data: SlashCommandBuilder | APIApplicationCommandSubcommandOption, + locale: Locale, +) => data.description_localizations?.[locale] ?? data.description;