TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 1 | import type Discord from "discord.js"; |
| 2 | import client from "./client.js"; |
| 3 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 4 | export const getCommandMentionByName = (name: string): string => { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 5 | const split = name.replaceAll("/", " ").split(" "); |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 6 | const commandName: string = split[0]!; |
| 7 | |
| 8 | const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName; |
| 9 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 10 | const command = client.fetchedCommands.filter((c) => filterCommand(c)); |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 11 | if (command.size === 0) return `\`/${name.replaceAll("/", " ")}\``; |
| 12 | const commandID = command.first()!.id; |
| 13 | return `</${split.join(" ")}:${commandID}>`; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 14 | }; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 15 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 16 | export const getCommandByName = (name: string): { name: string; description: string; mention: string } => { |
| 17 | const split = name.replaceAll(" ", "/"); |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 18 | const command = client.commands["commands/" + split]!; |
TheCodedProf | 8c29523 | 2023-01-27 20:52:24 -0500 | [diff] [blame] | 19 | // console.log(command) |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 20 | const mention = getCommandMentionByName(name); |
| 21 | return { |
| 22 | name: command[1].name, |
| 23 | description: command[1].description, |
| 24 | mention: mention |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame^] | 25 | }; |
| 26 | }; |