blob: b2b99377bb0f12fb370af8261c83df617a396a90 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import type Discord from "discord.js";
2import client from "./client.js";
3import config from "../config/main.json" assert { type: "json"};
4
5
6export const getCommandMentionByName = async (name: string): Promise<string> => {
7 const split = name.replaceAll("/", " ").split(" ")
8 const commandName: string = split[0]!;
9 let commandID: string;
10
11 const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName;
12
13 if (config.enableDevelopment) {
14 const developmentGuild = client.guilds.cache.get(config.developmentGuildID)!;
15 await developmentGuild.commands.fetch();
16 commandID = developmentGuild.commands.cache.filter(c => filterCommand(c)).first()!.id;
17 } else {
18 await client.application?.commands.fetch();
19 commandID = client.application?.commands.cache.filter(c => filterCommand(c)).first()!.id!;
20 }
21 return `</${split.join(" ")}:${commandID}>`;
22}