NotParcel/commands/products.js
2024-12-30 11:37:46 -07:00

24 lines
800 B
JavaScript

const client = global.discord_client
const pool = global.db_pool;
const execute = async (interaction) => {
try {
const [hub] = await pool.query(`SELECT * FROM hubs WHERE discordGuild = ?`, [interaction.guildId])
if (!hub) return interaction.reply({ content: "This server doesn't have a hub", ephemeral: true });
const products = await pool.query(`SELECT * FROM products WHERE hubId = ?`, [hub.id]);
const embed = {
title: hub.name,
fields: products.map(product => ({
name: product.name,
value: product.description
})),
color: 0x2F3136
}
return interaction.reply({ embeds: [embed] });
} catch (error) {
console.error(error);
return interaction.reply({ content: "An error occurred while fetching products", ephemeral: true });
}
};
module.exports = { execute }