From ceea161dc424897b5a4d7274f33a0063faa781c8 Mon Sep 17 00:00:00 2001 From: Slincnik Date: Tue, 14 Jan 2025 22:09:42 +0300 Subject: [PATCH] fix: devOnly validation --- src/handlers/command-handler/index.ts | 4 ++-- src/handlers/command-handler/validations/devOnly.ts | 12 ++++++++++++ src/index.ts | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/handlers/command-handler/index.ts b/src/handlers/command-handler/index.ts index af34a199..4775ee52 100644 --- a/src/handlers/command-handler/index.ts +++ b/src/handlers/command-handler/index.ts @@ -34,7 +34,7 @@ export class CommandHandler { const commandFilePaths = (await getFilePaths(cmdPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts")); for (const cmdFilePath of commandFilePaths) { - const { data, run } = await import(toFileURL(cmdFilePath)); + const { data, run, options } = await import(toFileURL(cmdFilePath)); if (!data || !data.name) { logger.warn(`Command ${cmdFilePath} does not have a data object or name`); @@ -46,7 +46,7 @@ export class CommandHandler { continue; } - this.commands.push({ data, run }); + this.commands.push({ data, run, options }); } } diff --git a/src/handlers/command-handler/validations/devOnly.ts b/src/handlers/command-handler/validations/devOnly.ts index ce8bdbbd..bb77637e 100644 --- a/src/handlers/command-handler/validations/devOnly.ts +++ b/src/handlers/command-handler/validations/devOnly.ts @@ -1,4 +1,5 @@ import { BuiltInValidationParams } from "@/types.js"; +import { ChannelType } from "discord.js"; export default function ({ interaction, targetCommand, client }: BuiltInValidationParams) { if (interaction.isAutocomplete()) return; @@ -7,6 +8,17 @@ export default function ({ interaction, targetCommand, client }: BuiltInValidati if (!targetCommand.options?.devOnly) return; + if (!interaction.isRepliable()) return; + + if (interaction.channel?.type === ChannelType.DM) { + interaction.reply({ + content: "❌ This command is only available in development servers.", + ephemeral: true, + }); + + return true; + } + if (interaction.inGuild() && !devGuildsIds.includes(interaction.guildId)) { interaction.reply({ content: "❌ This command is only available in development servers.", diff --git a/src/index.ts b/src/index.ts index 70f4de55..b66b509c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,11 @@ import { ExtendedClient } from "./structures/client.js"; import logger from "./helpers/logger.js"; import { CLIENT_INTENTS, CLIENT_ALLOWED_MENTIONS } from "./constants/index.js"; +import { Partials } from "discord.js"; const client = new ExtendedClient({ intents: CLIENT_INTENTS, + partials: [Partials.Channel], allowedMentions: CLIENT_ALLOWED_MENTIONS, });