add commands system
This commit is contained in:
22
src/handler/executeCommand.ts
Normal file
22
src/handler/executeCommand.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ChatInputCommandInteraction, CacheType } from "discord.js"
|
||||
import { execCmds } from "../cmd"
|
||||
|
||||
export async function execCmd(interaction: ChatInputCommandInteraction<CacheType>) {
|
||||
try {
|
||||
const commandName = interaction.commandName
|
||||
const command = execCmds.get(commandName)
|
||||
|
||||
console.info(`Executing command ${commandName} by ${interaction.user.tag} (${interaction.user.id})`)
|
||||
const options = interaction.options.data
|
||||
if (options.length > 0) {
|
||||
console.info(
|
||||
options.map(option => `\x1b[34m${option.name}\x1b[0m: \x1b[90m${option.value}\x1b[0m`).join(", ")
|
||||
)
|
||||
}
|
||||
|
||||
if (command) command.exec(interaction)
|
||||
else console.warn(`Command ${commandName} not found`)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user