25 lines
928 B
JavaScript
25 lines
928 B
JavaScript
const client = global.discord_client
|
|
const pool = global.db_pool;
|
|
|
|
const execute = async (interaction) => {
|
|
if (!interaction.guildId) return interaction.reply({ content: "This command can only be used in a server", ephemeral: true });
|
|
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 }
|