mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 08:45:55 +00:00
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
|
const UserInventory = require("../../models/UserInventory");
|
|
const ShopItem = require("../../models/ShopItem");
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName("inventory")
|
|
.setDescription("View your inventory with item rarity"),
|
|
|
|
async execute(interaction) {
|
|
const { user, guild } = interaction;
|
|
const inventory = await UserInventory.find({
|
|
userId: user.id,
|
|
guildId: guild.id,
|
|
});
|
|
|
|
if (inventory.length === 0) {
|
|
const emptyEmbed = new EmbedBuilder()
|
|
.setColor("#ff0000")
|
|
.setTitle("Inventory")
|
|
.setDescription("Your inventory is empty.")
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Requested by ${user.username}`,
|
|
iconURL: user.displayAvatarURL(),
|
|
});
|
|
|
|
await interaction.reply({ embeds: [emptyEmbed] });
|
|
return;
|
|
}
|
|
|
|
const itemDetails = await Promise.all(
|
|
inventory.map(async (item) => {
|
|
const shopItem = await ShopItem.findOne({ itemId: item.itemId });
|
|
if (item.quantity > 0) {
|
|
return `${shopItem.name} (x${item.quantity}) - **Rarity**: ${shopItem.rarity}`;
|
|
}
|
|
return null;
|
|
})
|
|
);
|
|
|
|
const filteredItemDetails = itemDetails.filter((detail) => detail !== null);
|
|
|
|
const inventoryEmbed = new EmbedBuilder()
|
|
.setColor("#00ff00")
|
|
.setTitle(`${user.username}'s Inventory`)
|
|
.setDescription(filteredItemDetails.join("\n"))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Requested by ${user.username}`,
|
|
iconURL: user.displayAvatarURL(),
|
|
});
|
|
|
|
await interaction.reply({ embeds: [inventoryEmbed] });
|
|
},
|
|
};
|