PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame^] | 1 | import type Discord from "discord.js"; |
| 2 | import client from "./client.js"; |
| 3 | import config from "../config/main.json" assert { type: "json"}; |
| 4 | |
| 5 | |
| 6 | export 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 | } |