aux function for retrieving correct message according to locales
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 26s
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 26s
This commit is contained in:
parent
97566bc0c5
commit
8703be8cd9
2 changed files with 36 additions and 10 deletions
|
@ -9,6 +9,7 @@ import {
|
||||||
import "../../modules/string";
|
import "../../modules/string";
|
||||||
import { getLocale, getLocalizations } from "../../utils/locales";
|
import { getLocale, getLocalizations } from "../../utils/locales";
|
||||||
import { getFilename } from "../../utils/misc";
|
import { getFilename } from "../../utils/misc";
|
||||||
|
import { goodDescription, goodName } from "../../utils/commands/help";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
scope: () => [],
|
scope: () => [],
|
||||||
|
@ -63,12 +64,16 @@ export default {
|
||||||
// Add subcommands
|
// Add subcommands
|
||||||
const all_commands: string[] = [];
|
const all_commands: string[] = [];
|
||||||
commands_name.forEach((command) => {
|
commands_name.forEach((command) => {
|
||||||
const json = client.commands.list.get(command)?.data.toJSON();
|
const data = client.commands.list.get(command)?.data;
|
||||||
all_commands.push(command);
|
const name = goodName(data!, interaction.locale);
|
||||||
|
all_commands.push(name);
|
||||||
|
|
||||||
json?.options
|
data
|
||||||
?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand)
|
?.toJSON()
|
||||||
.forEach((subcommand) => all_commands.push(command + " " + subcommand.name));
|
.options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand)
|
||||||
|
.forEach((subcommand) =>
|
||||||
|
all_commands.push(name + " " + goodName(subcommand, interaction.locale)),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const commands = all_commands.reduce(
|
const commands = all_commands.reduce(
|
||||||
|
@ -111,12 +116,10 @@ export default {
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setColor(Colors.Blurple)
|
.setColor(Colors.Blurple)
|
||||||
.setTitle("`/" + command.data.name + "`")
|
.setTitle("`/" + goodName(command.data, interaction.locale) + "`")
|
||||||
.setDescription(
|
.setDescription(
|
||||||
// Loads the description
|
// Loads the description according to the user's locals
|
||||||
// according to the user's locals
|
goodDescription(command.data, interaction.locale),
|
||||||
command.data.description_localizations?.[interaction.locale] ??
|
|
||||||
command.data.description,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
23
src/utils/commands/help.ts
Normal file
23
src/utils/commands/help.ts
Normal file
|
@ -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;
|
Loading…
Reference in a new issue