support argument
This commit is contained in:
parent
fe7b0ad5d7
commit
b3fb838920
1 changed files with 40 additions and 16 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
|
import { Locale } from 'discord-api-types/v9';
|
||||||
import { Client, CommandInteraction, MessageEmbed } from 'discord.js';
|
import { Client, CommandInteraction, MessageEmbed } from 'discord.js';
|
||||||
import { getLocale, getLocalizations } from '../../utils/locales';
|
import { getLocale, getLocalizations } from '../../utils/locales';
|
||||||
import { getFilename } from '../../utils/misc';
|
import { getFilename } from '../../utils/misc';
|
||||||
|
@ -7,15 +8,32 @@ export default {
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
return new SlashCommandBuilder()
|
return new SlashCommandBuilder()
|
||||||
.setName(filename.toLowerCase())
|
.setName(
|
||||||
.setDescription(client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? '')
|
filename.toLowerCase())
|
||||||
.setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true))
|
.setDescription(client.locales.get(client.config.default_lang)
|
||||||
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`));
|
?.get(`c_${filename}_desc`) ?? '')
|
||||||
|
.setNameLocalizations(
|
||||||
|
getLocalizations(client, `c_${filename}_name`, true))
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
getLocalizations(client, `c_${filename}_desc`))
|
||||||
|
.addStringOption(option => option
|
||||||
|
.setName(client.locales.get(client.config.default_lang)
|
||||||
|
?.get(`c_${filename}_opt1_name`) ?? '')
|
||||||
|
.setDescription(client.locales.get(client.config.default_lang)
|
||||||
|
?.get(`c_${filename}_opt1_desc`) ?? '')
|
||||||
|
.setNameLocalizations(
|
||||||
|
getLocalizations(client, `c_${filename}_opt1_name`, true))
|
||||||
|
.setDescriptionLocalizations(
|
||||||
|
getLocalizations(client, `c_${filename}_opt1_desc`))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
interaction: async (interaction: CommandInteraction, client: Client) => {
|
interaction: async (interaction: CommandInteraction, client: Client) => {
|
||||||
const loc = getLocale(client, interaction.locale);
|
const loc = getLocale(client, interaction.locale);
|
||||||
const desired_command = interaction.options.getString('command');
|
const desired_command = interaction.options.getString(client
|
||||||
|
.locales
|
||||||
|
.get(client.config.default_lang)
|
||||||
|
?.get(`c_${getFilename(__filename)}_opt1_name`) ?? '');
|
||||||
|
|
||||||
// If a command is specified
|
// If a command is specified
|
||||||
if (desired_command) {
|
if (desired_command) {
|
||||||
|
@ -28,20 +46,26 @@ export default {
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
client.commands.categories.forEach((commands_name, category) => {
|
client.commands.categories.forEach((commands_name, category) => {
|
||||||
const commands_description = commands_name.reduce((compteur, command_name) => {
|
const commands_description = commands_name.reduce(
|
||||||
const command = client.commands.list.get(command_name);
|
(compteur, command_name) => {
|
||||||
let res = `${compteur}- \`${command_name}\` : `;
|
const command = client.commands.list.get(command_name);
|
||||||
if (command?.data) {
|
let res = `${compteur}- \`${command_name}\` : `;
|
||||||
res += `${command.data.description}.\n`;
|
if (command?.data) {
|
||||||
} else {
|
const description =
|
||||||
res += `${loc.get('c_help3')}\n`;
|
command.data.description_localizations
|
||||||
}
|
?.[interaction.locale as Locale]
|
||||||
|
?? command.data.description;
|
||||||
|
|
||||||
return res;
|
res += `${description}\n`;
|
||||||
}, '');
|
} else {
|
||||||
|
res += `${loc.get('c_help3')}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}, '');
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: category,
|
name: category.toUpperCase(),
|
||||||
value: commands_description,
|
value: commands_description,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue