const { ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction, InteractionType } = require('discord.js');
const config = require('../../../ticketConfig.json');
module.exports = async (client, interaction) => {
console.log("Interaction received:", interaction);
if (interaction.type !== InteractionType.MessageComponent) {
console.log("Interaction is not of type MessageComponent.");
return;
}
if (!(interaction instanceof StringSelectMenuInteraction)) {
console.log("Interaction is not an instance of StringSelectMenuInteraction.");
return;
}
if (!interaction.customId.startsWith('select_category_')) {
console.log("customId does not start with 'select_category_'.");
return;
}
const selectedCategory = config.categories.find(category => category.name.toLowerCase() === interaction.values[0]);
if (!selectedCategory) {
console.log("Selected category not found.");
return;
}
const categoryEmoji = selectedCategory.emoji
? parseEmoji(selectedCategory.emoji)
: undefined;
const items = selectedCategory.items.map(item => {
return {
label: item.name,
value: item.id
};
});
console.log("Mapped items:", items);
console.log("Category emoji:", categoryEmoji);
try {
const itemMenu = new StringSelectMenuBuilder()
.setCustomId(`select_item_${selectedCategory.name.toLowerCase()}`)
.setPlaceholder('Select an item')
.addOptions(items);
const row = new ActionRowBuilder().addComponents(itemMenu);
await interaction.update({
content: `Please select an item from **${selectedCategory.name}** ${categoryEmoji ? `<:${categoryEmoji.name}:${categoryEmoji.id}>` : ''}:`,
components: [row],
ephemeral: true
});
} catch (err) {
console.log("Error during menu creation or interaction update:", err);
}
};
function parseEmoji(emojiString) {
const [name, id] = emojiString.split(':');
return { name, id };
}