const { EmbedBuilder } = require('discord.js'); const handleError = require('../utils/errorHandler'); const User = require('../models/User'); module.exports = { execute: async (interaction, client) => { // ✅ Handle Autocomplete if (interaction.isAutocomplete()) { const command = client.commands.get(interaction.commandName); if (!command?.autocomplete) return; try { await command.autocomplete(interaction, client); } catch (err) { console.error('❌ Autocomplete error:', err); } return; } // ✅ Handle Modal Submit if (interaction.isModalSubmit() && interaction.customId === 'profileCreate') { const userId = interaction.user.id; const name = interaction.fields.getTextInputValue('name').trim(); const specialty = interaction.fields.getTextInputValue('specialty')?.trim() || null; const bio = interaction.fields.getTextInputValue('bio')?.trim() || null; try { await User.create({ userId, detectiveName: name, specialty, bio, coins: 200, xp: 0, level: 1, solved: 0, failed: 0, activeEffects: [] }); const embed = new EmbedBuilder() .setTitle(`✅ Profile Created: ${name}`) .setDescription(`Welcome, detective. Your career begins now.`) .addFields( { name: '🎯 Specialty', value: specialty || '_None_', inline: true }, { name: '🪙 Starter Coins', value: '200', inline: true }, ...(bio ? [{ name: '📖 Bio', value: bio }] : []) ) .setColor(0x3498db) .setFooter({ text: 'Use /case to begin your first mystery.' }) .setTimestamp(); await interaction.reply({ embeds: [embed], ephemeral: false }); } catch (err) { console.error('❌ Modal failed:', err); await interaction.reply({ content: 'Profile creation failed.', ephemeral: false }); } return; } // ✅ Handle Slash Commands if (interaction.isChatInputCommand()) { const command = client.commands.get(interaction.commandName); if (!command) return; try { await interaction.deferReply({ ephemeral: false }); await command.execute(interaction, client); } catch (error) { await handleError(error, interaction, client); } } } };