changed wording on guide and updated commandmentionbyname
diff --git a/src/utils/client.ts b/src/utils/client.ts
index a199b5b..2e2baa6 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -1,3 +1,4 @@
+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";
@@ -23,6 +24,7 @@
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, {
command: Discord.SlashCommandBuilder |
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index abc8c39..b4c6e6e 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -208,12 +208,20 @@
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/getCommandMentionByName.ts b/src/utils/getCommandMentionByName.ts
index b2b9937..e5a67c5 100644
--- a/src/utils/getCommandMentionByName.ts
+++ b/src/utils/getCommandMentionByName.ts
@@ -1,22 +1,15 @@
import type Discord from "discord.js";
import client from "./client.js";
-import config from "../config/main.json" assert { type: "json"};
export const getCommandMentionByName = async (name: string): Promise<string> => {
const split = name.replaceAll("/", " ").split(" ")
const commandName: string = split[0]!;
- let commandID: string;
const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName;
- if (config.enableDevelopment) {
- const developmentGuild = client.guilds.cache.get(config.developmentGuildID)!;
- await developmentGuild.commands.fetch();
- commandID = developmentGuild.commands.cache.filter(c => filterCommand(c)).first()!.id;
- } else {
- await client.application?.commands.fetch();
- commandID = client.application?.commands.cache.filter(c => filterCommand(c)).first()!.id!;
- }
+ const command = client.commandList!.filter(c => filterCommand(c))
+ if (command.size === 0) return `\`/${name.replaceAll("/", " ")}\``;
+ const commandID = command.first()!.id;
return `</${split.join(" ")}:${commandID}>`;
-}
\ No newline at end of file
+}