console.log('INTERACTION CREATE EVENT IS WORKING!!!') const { Events } = require('discord.js'); const client = require("../index").client; const { hasPermissionOrDev } = require('../utils/developers'); client.on(Events.InteractionCreate, async (interaction) => { try { if (interaction.isCommand()) { const command = client.SlashCmds.get(interaction.commandName); if (command) { await command.run(client, interaction); } return; } if (interaction.isButton()) { const giveawayManager = client.giveawayManager; if (interaction.customId.startsWith('giveaway_enter_')) { const giveaway = giveawayManager.getGiveaway(interaction.message.id); if (!giveaway) { return await interaction.reply({ content: 'This giveaway no longer exists.', ephemeral: true }); } if (giveaway.ended) { return await interaction.reply({ content: 'This giveaway has already ended.', ephemeral: true }); } if (giveaway.entries.includes(interaction.user.id)) { await interaction.deferReply({ ephemeral: true }); await giveawayManager.removeEntry(interaction.message.id, interaction.user.id); return await interaction.editReply({ content: 'You have left the giveaway!' }); } await interaction.deferReply({ ephemeral: true }); const userEntryCount = await giveawayManager.addEntry( interaction.message.id, interaction.user.id, interaction.member ); if (userEntryCount) { await interaction.editReply({ content: '**You have successfully joined this giveaway!**' }); const updatedGiveaway = giveawayManager.getGiveaway(interaction.message.id); const totalEntries = giveawayManager.getTotalEntries(updatedGiveaway); const winChance = totalEntries > 0 ? ((giveaway.winners / totalEntries) * 100).toFixed(2) : '0.00'; const entryText = userEntryCount === 1 ? 'entry' : 'entries'; await interaction.followUp({ content: `**You now have ${userEntryCount} ${entryText} in this giveaway!**\n` + `Total entries: **${totalEntries}**\n` + `Your win chance: **${winChance}%**`, ephemeral: true }); } return; } if (interaction.customId.startsWith('giveaway_end_')) { if (!hasPermissionOrDev(interaction.member, 'MANAGE_GUILD')) { return await interaction.reply({ content: 'You need `MANAGE_GUILD` permission to end a giveaway.', ephemeral: true }); } const giveaway = giveawayManager.getGiveaway(interaction.message.id); if (!giveaway) { return await interaction.reply({ content: 'This giveaway no longer exists.', ephemeral: true }); } if (giveaway.ended) { return await interaction.reply({ content: 'This giveaway has already ended.', ephemeral: true }); } await giveawayManager.endGiveaway(interaction.message.id); return await interaction.reply({ content: 'Giveaway ended successfully!', ephemeral: true }); } } // =================================================================== // 3. OTHER COMPONENTS (Select Menus, Modals, etc.) // =================================================================== // Add more here in the future if needed: // if (interaction.isStringSelectMenu()) { ... } // if (interaction.isModalSubmit()) { ... } } catch (error) { console.error('Error in interactionCreate:', error); const errorMessage = { content: 'There was an error while processing your interaction!', ephemeral: true }; try { if (interaction.replied || interaction.deferred) { await interaction.followUp(errorMessage); } else { await interaction.reply(errorMessage); } } catch (replyError) { console.error('Failed to send error message to user:', replyError); } } }); // Copyright - Made with ❤ by DevArqf