fix: devOnly validation

This commit is contained in:
Slincnik 2025-01-14 22:09:42 +03:00
parent 6c7f892ae4
commit ceea161dc4
No known key found for this signature in database
3 changed files with 16 additions and 2 deletions

View file

@ -34,7 +34,7 @@ export class CommandHandler {
const commandFilePaths = (await getFilePaths(cmdPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts")); const commandFilePaths = (await getFilePaths(cmdPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts"));
for (const cmdFilePath of commandFilePaths) { for (const cmdFilePath of commandFilePaths) {
const { data, run } = await import(toFileURL(cmdFilePath)); const { data, run, options } = await import(toFileURL(cmdFilePath));
if (!data || !data.name) { if (!data || !data.name) {
logger.warn(`Command ${cmdFilePath} does not have a data object or name`); logger.warn(`Command ${cmdFilePath} does not have a data object or name`);
@ -46,7 +46,7 @@ export class CommandHandler {
continue; continue;
} }
this.commands.push({ data, run }); this.commands.push({ data, run, options });
} }
} }

View file

@ -1,4 +1,5 @@
import { BuiltInValidationParams } from "@/types.js"; import { BuiltInValidationParams } from "@/types.js";
import { ChannelType } from "discord.js";
export default function ({ interaction, targetCommand, client }: BuiltInValidationParams) { export default function ({ interaction, targetCommand, client }: BuiltInValidationParams) {
if (interaction.isAutocomplete()) return; if (interaction.isAutocomplete()) return;
@ -7,6 +8,17 @@ export default function ({ interaction, targetCommand, client }: BuiltInValidati
if (!targetCommand.options?.devOnly) return; 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)) { if (interaction.inGuild() && !devGuildsIds.includes(interaction.guildId)) {
interaction.reply({ interaction.reply({
content: "❌ This command is only available in development servers.", content: "❌ This command is only available in development servers.",

View file

@ -1,9 +1,11 @@
import { ExtendedClient } from "./structures/client.js"; import { ExtendedClient } from "./structures/client.js";
import logger from "./helpers/logger.js"; import logger from "./helpers/logger.js";
import { CLIENT_INTENTS, CLIENT_ALLOWED_MENTIONS } from "./constants/index.js"; import { CLIENT_INTENTS, CLIENT_ALLOWED_MENTIONS } from "./constants/index.js";
import { Partials } from "discord.js";
const client = new ExtendedClient({ const client = new ExtendedClient({
intents: CLIENT_INTENTS, intents: CLIENT_INTENTS,
partials: [Partials.Channel],
allowedMentions: CLIENT_ALLOWED_MENTIONS, allowedMentions: CLIENT_ALLOWED_MENTIONS,
}); });