Inventory
Shop Command
The shop command displays available items for purchase, organized by categories, with interactive navigation and purchase options. This command is available to all users.
Command Details
- Name: shop
- Aliases: store
- Category: Inventory
- Description: View which items you can buy
- Usage:
shop [category]
- Examples:
shop
store
- Cooldown: 5 seconds
- Arguments: Optional (category)
- Slash Command: Enabled
- Permissions:
- Bot: SendMessages, ViewChannel, EmbedLinks
- User: None
- Player Requirements: None
Functionality
- Retrieves shop data from
ShopItems
and organizes items by unique categories. - Displays a list of items in the selected category (defaulting to the first category) with pagination (8 items per page).
- Supports interactive navigation via a category dropdown, item dropdown, and Previous/Next/Home buttons.
- Allows viewing detailed item information (ID, price, type, description) and initiating purchases.
- Provides a purchase confirmation interface with quantity adjustment buttons (
+
,-
) and Confirm/Cancel options. - Validates purchases, checking user balance and updating inventory and coins via the
Users
schema. - Sends localized messages for success, errors, and confirmations, with a 5-minute interaction timeout.
- Handles errors like invalid categories, insufficient funds, or database issues with appropriate messages.
Code Overview
The command:
- Extends the
Command
class from../../structures/index.js
. - Imports
Users
schema andShopItems
for shop data. - Uses the
run
method to handle message and slash command inputs, defaulting to the first category if none is specified. - Implements
showShop
to manage the interactive interface with state tracking (category, page, selected item, purchase mode). - Generates embeds for list view, item details, and purchase confirmation using
client.embed()
. - Creates dropdowns (
StringSelectMenuBuilder
) for category and item selection, and buttons (ButtonBuilder
) for navigation and purchase actions. - Uses a
MessageComponentCollector
to handle interactions, updating the display dynamically. - Processes purchases by updating the database (
Users.updateOne
) and sending ephemeral success/error messages. - Disables components on timeout (5 minutes) and logs errors for debugging.
Sell Command
The sell command allows users to sell items or entire categories from their inventory for coins, with an interactive interface for quantity selection. This command is available to all users with sellable items.
Use Command
The use command allows users to apply themes, wallpapers, colors, tools, or potions from their inventory to customize their profile or gain temporary buffs. This command is available to all users with relevant items.