Finished Help, fixed command registration

pull/11/head
TheCodedProf 3 years ago
parent f86ba0999d
commit fe0a786c39

@ -120,7 +120,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
new StringSelectMenuOptionBuilder().setLabel("Select a subcommand").setValue("none").setDefault(currentPath[1] === "none"), new StringSelectMenuOptionBuilder().setLabel("Select a subcommand").setValue("none").setDefault(currentPath[1] === "none"),
...subcommandGroups.map((option) => new StringSelectMenuOptionBuilder().setLabel(capitalize(option.name)).setValue(option.name).setDefault(currentPath[1] === option.name)) ...subcommandGroups.map((option) => new StringSelectMenuOptionBuilder().setLabel(capitalize(option.name)).setValue(option.name).setDefault(currentPath[1] === option.name))
) )
if(subcommandGroupRow.components[0]!.options.find((option) => option.data.default)) { if(subcommandGroupRow.components[0]!.options.find((option) => option.data.default && option.data.value !== "none")) {
let subsubcommands = (subcommandGroups.find((option) => option.name === currentPath[1])! as ApplicationCommandSubGroup).options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) || []; let subsubcommands = (subcommandGroups.find((option) => option.name === currentPath[1])! as ApplicationCommandSubGroup).options?.filter((option) => option.type === ApplicationCommandOptionType.Subcommand) || [];
subcommandRow.components[0]! subcommandRow.components[0]!
.addOptions( .addOptions(
@ -163,7 +163,6 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
currentPath[2] = value; currentPath[2] = value;
break; break;
} }
console.log(currentPath)
} while (!closed); } while (!closed);
}; };

@ -27,8 +27,8 @@ async function registerCommands() {
const last = i === files.length - 1 ? "└" : "├"; const last = i === files.length - 1 ? "└" : "├";
if (file.isDirectory()) { if (file.isDirectory()) {
console.log(`${last}${colours.yellow}Loading subcommands of ${file.name}${colours.none}`) console.log(`${last}${colours.yellow}Loading subcommands of ${file.name}${colours.none}`)
const fetched = (await import(`../../../${config.commandsFolder}/${file.name}/_meta.js`)).command; const fetched = (await import(`../../../${config.commandsFolder}/${file.name}/_meta.js`));
commands.push(fetched); commands.push(fetched.command);
} else if (file.name.endsWith(".js")) { } else if (file.name.endsWith(".js")) {
console.log(`${last}${colours.yellow}Loading command ${file.name}${colours.none}`) console.log(`${last}${colours.yellow}Loading command ${file.name}${colours.none}`)
const fetched = (await import(`../../../${config.commandsFolder}/${file.name}`)); const fetched = (await import(`../../../${config.commandsFolder}/${file.name}`));
@ -171,6 +171,7 @@ async function registerCommandHandler() {
const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : ""); const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : "");
console.log(fullCommandName, client.commands[fullCommandName])
const command = client.commands[fullCommandName]![0]; const command = client.commands[fullCommandName]![0];
const callback = command?.callback; const callback = command?.callback;
const check = command?.check; const check = command?.check;
@ -222,4 +223,5 @@ export default async function register() {
console.log( console.log(
(config.enableDevelopment ? `${colours.purple}Bot started in Development mode` : (config.enableDevelopment ? `${colours.purple}Bot started in Development mode` :
`${colours.blue}Bot started in Production mode`) + colours.none) `${colours.blue}Bot started in Production mode`) + colours.none)
console.log(client.commands)
}; };

@ -1,4 +1,4 @@
import type { SlashCommandSubcommandGroupBuilder } from "discord.js"; import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js";
import type { SlashCommandBuilder } from "discord.js"; import type { SlashCommandBuilder } from "discord.js";
import config from "../../config/main.json" assert { type: "json" }; import config from "../../config/main.json" assert { type: "json" };
import getSubcommandsInFolder from "./getFilesInFolder.js"; import getSubcommandsInFolder from "./getFilesInFolder.js";
@ -32,7 +32,9 @@ export async function group(
if (descriptionLocalizations) { subcommandGroup.setDescriptionLocalizations(descriptionLocalizations) } if (descriptionLocalizations) { subcommandGroup.setDescriptionLocalizations(descriptionLocalizations) }
for (const subcommand of fetched.subcommands) { for (const subcommand of fetched.subcommands) {
subcommandGroup.addSubcommand(subcommand.command); let processedCommand = subcommand.command(new SlashCommandSubcommandBuilder());
client.commands["commands/" + path + "/" + processedCommand.name] = [subcommand, { name: processedCommand.name, description: processedCommand.description }]
subcommandGroup.addSubcommand(processedCommand);
}; };
return subcommandGroup; return subcommandGroup;
@ -53,6 +55,8 @@ export async function command(
commandString = "commands/" + (commandString ?? path); commandString = "commands/" + (commandString ?? path);
const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path); const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path);
console.log(`│ ├─ ${fetched.errors ? colours.red : colours.green}Loaded ${fetched.subcommands.length} subcommands and ${fetched.subcommandGroups.length} subcommand groups for ${name} (${fetched.errors} failed)${colours.none}`) console.log(`│ ├─ ${fetched.errors ? colours.red : colours.green}Loaded ${fetched.subcommands.length} subcommands and ${fetched.subcommandGroups.length} subcommand groups for ${name} (${fetched.errors} failed)${colours.none}`)
console.log({name: name, description: description})
client.commands[commandString!] = [undefined, { name: name, description: description }]
return (command: SlashCommandBuilder) => { return (command: SlashCommandBuilder) => {
command.setName(name) command.setName(name)
command.setDescription(description) command.setDescription(description)
@ -64,12 +68,11 @@ export async function command(
bitfield.add(userPermissions) bitfield.add(userPermissions)
command.setDefaultMemberPermissions(bitfield.bitfield) command.setDefaultMemberPermissions(bitfield.bitfield)
} }
client.commands[commandString!] = [undefined, { name: name, description: description }]
for (const subcommand of fetched.subcommands) { for (const subcommand of fetched.subcommands) {
let fetchedCommand; let fetchedCommand;
if (subcommand.command instanceof Function) { if (subcommand.command instanceof Function) {
fetchedCommand = subcommand.command(new Discord.SlashCommandSubcommandBuilder()); fetchedCommand = subcommand.command(new SlashCommandSubcommandBuilder());
} else { } else {
fetchedCommand = subcommand.command; fetchedCommand = subcommand.command;
} }
@ -77,8 +80,9 @@ export async function command(
command.addSubcommand(fetchedCommand); command.addSubcommand(fetchedCommand);
} }
for (const group of fetched.subcommandGroups) { for (const group of fetched.subcommandGroups) {
command.addSubcommandGroup(group.command); let processedCommand = group.command(new SlashCommandSubcommandGroupBuilder());
client.commands[commandString! + "/" + group.command.name] = [undefined, { name: group.command.name, description: group.command.description }] client.commands[commandString! + "/" + processedCommand.name] = [undefined, { name: processedCommand.name, description: processedCommand.description }]
command.addSubcommandGroup(processedCommand);
}; };
return command; return command;
}; };

@ -183,7 +183,7 @@ class confirmationMessage {
let component; let component;
try { try {
component = await m.awaitMessageComponent({ component = await m.awaitMessageComponent({
filter: (i) => i.user.id === this.interaction.user.id && i.channel!.id === this.interaction.channel!.id && i.id === m.id, filter: (i) => i.user.id === this.interaction.user.id && i.channel!.id === this.interaction.channel!.id,
time: 300000 time: 300000
}); });
} catch (e) { } catch (e) {

@ -18,6 +18,7 @@ export const getCommandByName = (name: string): {name: string, description: stri
const split = name.replaceAll(" ", "/") const split = name.replaceAll(" ", "/")
const command = client.commands["commands/" + split]!; const command = client.commands["commands/" + split]!;
console.log(command)
const mention = getCommandMentionByName(name); const mention = getCommandMentionByName(name);
return { return {
name: command[1].name, name: command[1].name,

Loading…
Cancel
Save