import NDBClient from "@Client/NDBClient"; import { EventOptions } from "~/Types"; import { CommandTools, InteractionTools } from "~/Utils/Tools"; import { BaseEvent, BaseCommand } from "@Utils/Structures"; import { CommandInteraction, CommandInteractionOptionResolver, Interaction, User, } from "discord.js"; module.exports = class SlashCommandEvent extends BaseEvent { constructor(client: NDBClient) { const options: EventOptions = { name: "SlashCommand", type: "on", emitter: "client", enable: true, }; super(client, options); } async run(client: NDBClient, interaction: CommandInteraction) { const UserProfile = await client.Mongoose.FindUserProfile( interaction.member.user as User ); if (!UserProfile) { await client.Mongoose.CreateUserProfile( interaction as Interaction, interaction.user ); } await client.Mongoose.AddGuildToProfile( interaction as Interaction, interaction.user ); const cmdTools = new CommandTools(client); const _Command: BaseCommand = client.Collections.SlashCommands.get( interaction.commandName ) as BaseCommand; if (_Command) { const Checker = await cmdTools.runCheck( interaction, _Command, "interaction", UserProfile ); if (Checker) { await interaction .deferReply({ ephemeral: _Command.options.SlashOptions.ephemeral, }) .catch((e) => {}); _Command .SlashRun( client, interaction, interaction.options as CommandInteractionOptionResolver ) .catch(async (error: Error) => { client.logger.error(error.stack); return; }); } } } };