removed discordjs/builders, worked on help
diff --git a/src/utils/client.ts b/src/utils/client.ts
index 2e2baa6..2a0702a 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -1,4 +1,3 @@
-import { ApplicationCommand, ApplicationCommandResolvable, DataManager } from 'discord.js';
import Discord, { Client, Interaction, AutocompleteInteraction, GatewayIntentBits, Collection } from 'discord.js';
import { Logger } from "../utils/log.js";
import Memory from "../utils/memory.js";
@@ -24,16 +23,15 @@
eventScheduler: EventScheduler;
performanceTest: PerformanceTest;
};
- commandList?: Discord.Collection<string, Discord.ApplicationCommand>;
preloadPage: Record<string, {command: string, argument: string}> = {}; // e.g. { channelID: { command: privacy, page: 3}}
- commands: Record<string, {
+ commands: Record<string, [{
command: Discord.SlashCommandBuilder |
((builder: Discord.SlashCommandBuilder) => Discord.SlashCommandBuilder) |
Discord.SlashCommandSubcommandBuilder | ((builder: Discord.SlashCommandSubcommandBuilder) => Discord.SlashCommandSubcommandBuilder) | Discord.SlashCommandSubcommandGroupBuilder | ((builder: Discord.SlashCommandSubcommandGroupBuilder) => Discord.SlashCommandSubcommandGroupBuilder),
callback: (interaction: Interaction) => Promise<void>,
- check: (interaction: Interaction) => Promise<boolean> | boolean,
+ check: (interaction: Interaction, partial: boolean) => Promise<boolean> | boolean,
autocomplete: (interaction: AutocompleteInteraction) => Promise<string[]>
- }> = {};
+ } | undefined,{name: string, description: string}]> = {};
fetchedCommands: Collection<string, Discord.ApplicationCommand> = new Collection();
constructor(database: typeof NucleusClient.prototype.database) {
super({ intents: [
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index b4c6e6e..4290064 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -35,9 +35,12 @@
fetched.command.setDMPermission(fetched.allowedInDMs ?? false)
fetched.command.setNameLocalizations(fetched.nameLocalizations ?? {})
fetched.command.setDescriptionLocalizations(fetched.descriptionLocalizations ?? {})
- if (fetched.nameLocalizations || fetched.descriptionLocalizations) console.log("AAAAA")
+ // if (fetched.nameLocalizations || fetched.descriptionLocalizations)
commands.push(fetched.command);
- client.commands["commands/" + fetched.command.name] = fetched;
+ client.commands["commands/" + fetched.command.name] = [
+ fetched,
+ {name: fetched.name ?? fetched.command.name, description: fetched.description ?? fetched.command.description}
+ ];
}
i++;
console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colours.green}Loaded ${file.name} [${i} / ${files.length}]${colours.none}`)
@@ -142,11 +145,11 @@
client.on("interactionCreate", async (interaction: Interaction) => {
if (interaction.isUserContextMenuCommand()) {;
const commandName = "contextCommands/user/" + interaction.commandName;
- execute(client.commands[commandName]?.check, client.commands[commandName]?.callback, interaction)
+ execute(client.commands[commandName]![0]?.check, client.commands[commandName]![0]?.callback, interaction)
return;
} else if (interaction.isMessageContextMenuCommand()) {
const commandName = "contextCommands/message/" + interaction.commandName;
- execute(client.commands[commandName]?.check, client.commands[commandName]?.callback, interaction)
+ execute(client.commands[commandName]![0]?.check, client.commands[commandName]![0]?.callback, interaction)
return;
} else if (interaction.isAutocomplete()) {
const commandName = interaction.commandName;
@@ -155,7 +158,7 @@
const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : "");
- const choices = await client.commands[fullCommandName]?.autocomplete(interaction);
+ const choices = await client.commands[fullCommandName]![0]?.autocomplete(interaction);
const formatted = (choices ?? []).map(choice => {
return { name: choice, value: choice }
@@ -168,7 +171,7 @@
const fullCommandName = "commands/" + commandName + (subcommandGroupName ? `/${subcommandGroupName}` : "") + (subcommandName ? `/${subcommandName}` : "");
- const command = client.commands[fullCommandName];
+ const command = client.commands[fullCommandName]![0];
const callback = command?.callback;
const check = command?.check;
execute(check, callback, interaction);
@@ -208,20 +211,11 @@
const guild = await client.guilds.fetch(config.developmentGuildID);
console.log(`${colours.purple}Registering commands in ${guild!.name}${colours.none}`)
await guild.commands.set(commandList);
- client.commandList = guild.commands.cache;
} else {
console.log(`${colours.blue}Registering commands in production mode${colours.none}`)
await client.application?.commands.set(commandList);
}
}
- if (config.enableDevelopment) {
- const guild = await client.guilds.fetch(config.developmentGuildID);
- await guild.commands.fetch();
- client.commandList = guild.commands.cache;
- } else {
- await client.application?.commands.fetch();
- client.commandList = client.application?.commands.cache!;
- }
await registerCommandHandler();
await registerEvents();
console.log(`${colours.green}Registered commands, events and context menus${colours.none}`)
diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts
index b2927d6..a4474ac 100644
--- a/src/utils/commandRegistration/slashCommandBuilder.ts
+++ b/src/utils/commandRegistration/slashCommandBuilder.ts
@@ -1,4 +1,4 @@
-import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
+import type { SlashCommandSubcommandGroupBuilder } from "discord.js";
import type { SlashCommandBuilder } from "discord.js";
import config from "../../config/main.json" assert { type: "json" };
import getSubcommandsInFolder from "./getFilesInFolder.js";
@@ -64,6 +64,7 @@
bitfield.add(userPermissions)
command.setDefaultMemberPermissions(bitfield.bitfield)
}
+ client.commands[commandString!] = [undefined, { name: name, description: description }]
for (const subcommand of fetched.subcommands) {
let fetchedCommand;
@@ -72,11 +73,12 @@
} else {
fetchedCommand = subcommand.command;
}
- client.commands[commandString! + "/" + fetchedCommand.name] = subcommand
+ client.commands[commandString! + "/" + fetchedCommand.name] = [subcommand, { name: fetchedCommand.name, description: fetchedCommand.description }]
command.addSubcommand(fetchedCommand);
}
for (const group of fetched.subcommandGroups) {
command.addSubcommandGroup(group.command);
+ client.commands[commandString! + "/" + group.command.name] = [undefined, { name: group.command.name, description: group.command.description }]
};
return command;
};
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index 6dc424e..18bcd7b 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -1,4 +1,4 @@
-import { TextInputBuilder } from "@discordjs/builders";
+import { TextInputBuilder } from "discord.js";
import Discord, {
CommandInteraction,
Interaction,
@@ -280,7 +280,7 @@
await this.timeoutError()
returnValue.cancelled = true;
}
- if (success == false) {
+ if (success === false) {
await this.interaction.editReply({
embeds: [new EmojiEmbed()
.setTitle(this.title)
diff --git a/src/utils/generateEmojiEmbed.ts b/src/utils/generateEmojiEmbed.ts
index 2978176..a326fc5 100644
--- a/src/utils/generateEmojiEmbed.ts
+++ b/src/utils/generateEmojiEmbed.ts
@@ -1,4 +1,4 @@
-import { EmbedBuilder } from "@discordjs/builders";
+import { EmbedBuilder } from "discord.js";
import getEmojiByName from "./getEmojiByName.js";
const colors = {
diff --git a/src/utils/getCommandDataByName.ts b/src/utils/getCommandDataByName.ts
new file mode 100644
index 0000000..0d4ac47
--- /dev/null
+++ b/src/utils/getCommandDataByName.ts
@@ -0,0 +1,27 @@
+import type Discord from "discord.js";
+import client from "./client.js";
+
+
+export const getCommandMentionByName = (name: string): string => {
+ const split = name.replaceAll("/", " ").split(" ")
+ const commandName: string = split[0]!;
+
+ const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName;
+
+ const command = client.fetchedCommands.filter(c => filterCommand(c))
+ if (command.size === 0) return `\`/${name.replaceAll("/", " ")}\``;
+ const commandID = command.first()!.id;
+ return `</${split.join(" ")}:${commandID}>`;
+}
+
+export const getCommandByName = (name: string): {name: string, description: string, mention: string} => {
+
+ const split = name.replaceAll(" ", "/")
+ const command = client.commands["commands/" + split]!;
+ const mention = getCommandMentionByName(name);
+ return {
+ name: command[1].name,
+ description: command[1].description,
+ mention: mention
+ }
+}
\ No newline at end of file
diff --git a/src/utils/getCommandMentionByName.ts b/src/utils/getCommandMentionByName.ts
deleted file mode 100644
index e5a67c5..0000000
--- a/src/utils/getCommandMentionByName.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import type Discord from "discord.js";
-import client from "./client.js";
-
-
-export const getCommandMentionByName = async (name: string): Promise<string> => {
- const split = name.replaceAll("/", " ").split(" ")
- const commandName: string = split[0]!;
-
- const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName;
-
- const command = client.commandList!.filter(c => filterCommand(c))
- if (command.size === 0) return `\`/${name.replaceAll("/", " ")}\``;
- const commandID = command.first()!.id;
- return `</${split.join(" ")}:${commandID}>`;
-}