hide unavailable commands and add subcommands (fix #47)
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 27s
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 27s
This commit is contained in:
parent
750c6b4447
commit
97566bc0c5
2 changed files with 31 additions and 8 deletions
|
@ -1,5 +1,11 @@
|
||||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||||
import { ChatInputCommandInteraction, Client, Colors, EmbedBuilder } from "discord.js";
|
import {
|
||||||
|
ApplicationCommandOptionType,
|
||||||
|
ChatInputCommandInteraction,
|
||||||
|
Client,
|
||||||
|
Colors,
|
||||||
|
EmbedBuilder,
|
||||||
|
} from "discord.js";
|
||||||
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";
|
||||||
|
@ -47,16 +53,31 @@ export default {
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
// Load all the command per categories
|
// Load all the command per categories
|
||||||
// TODO: Check if the command exist in the context (guild)
|
|
||||||
// TODO: List subcommands too
|
|
||||||
// https://git.mylloon.fr/ConfrerieDuKassoulait/Botanique/issues/47
|
|
||||||
client.commands.categories.forEach((commands_name, category) => {
|
client.commands.categories.forEach((commands_name, category) => {
|
||||||
const commands = commands_name.reduce((data, command_name) => {
|
// Check if the command exist in the context (guild)
|
||||||
return data + `\`/${command_name}\`, `;
|
commands_name = commands_name.filter((command) => {
|
||||||
}, "");
|
const scope = client.commands.list.get(command)?.scope();
|
||||||
|
return scope!.length === 0 || scope?.find((v) => v === interaction.guildId) !== undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add subcommands
|
||||||
|
const all_commands: string[] = [];
|
||||||
|
commands_name.forEach((command) => {
|
||||||
|
const json = client.commands.list.get(command)?.data.toJSON();
|
||||||
|
all_commands.push(command);
|
||||||
|
|
||||||
|
json?.options
|
||||||
|
?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand)
|
||||||
|
.forEach((subcommand) => all_commands.push(command + " " + subcommand.name));
|
||||||
|
});
|
||||||
|
|
||||||
|
const commands = all_commands.reduce(
|
||||||
|
(data, command_name) => data + `\`/${command_name}\`, `,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: category.capitalize() + ` (${commands_name.length})`,
|
name: category.capitalize() + ` (${all_commands.length})`,
|
||||||
value: commands.slice(0, -2),
|
value: commands.slice(0, -2),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,6 +75,8 @@ declare module "discord.js" {
|
||||||
string,
|
string,
|
||||||
/** Command itself */
|
/** Command itself */
|
||||||
{
|
{
|
||||||
|
/** Guilds where the command is active */
|
||||||
|
scope: () => string[];
|
||||||
/** Data about the command */
|
/** Data about the command */
|
||||||
data: SlashCommandBuilder;
|
data: SlashCommandBuilder;
|
||||||
/** How the command interact */
|
/** How the command interact */
|
||||||
|
|
Loading…
Reference in a new issue