PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import type Discord from "discord.js"; |
| 2 | import client from "./client.js"; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 3 | |
| 4 | |
| 5 | export const getCommandMentionByName = async (name: string): Promise<string> => { |
| 6 | const split = name.replaceAll("/", " ").split(" ") |
| 7 | const commandName: string = split[0]!; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 8 | |
| 9 | const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName; |
| 10 | |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame^] | 11 | const command = client.commandList!.filter(c => filterCommand(c)) |
| 12 | if (command.size === 0) return `\`/${name.replaceAll("/", " ")}\``; |
| 13 | const commandID = command.first()!.id; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 14 | return `</${split.join(" ")}:${commandID}>`; |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame^] | 15 | } |