Inventory
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.
Command Details
- Name: sell
- Aliases: None
- Category: Inventory
- Description: Sell an item or category from your inventory
- Usage:
sell <item_id | category> [amount] - Examples:
sell coalsell coal 5sell resourcessell all
- Cooldown: 5 seconds
- Arguments: Yes (item ID or category, optional amount)
- Slash Command: Enabled
- Permissions:
- Bot: SendMessages, ViewChannel, EmbedLinks
- User: None
- Player Requirements: Must have sellable items in inventory
Functionality
- Retrieves the user's inventory from the
Usersschema and checks for sellable items fromShopItems,ImportantItems,Woods,Minerals,SlimeCategory, andTools. - Supports selling individual items by ID, entire categories (e.g.,
resources,card), or all sellable items (sell all). - For individual items, provides an interactive interface with buttons to adjust quantity (
+,-,1,Half,All), confirm, or cancel the sale. - For categories or
all, displays a confirmation embed listing items to be sold and their total value, with Confirm/Cancel buttons. - Validates inputs, ensuring items are sellable, owned, and the quantity is valid (supports
all,half, or numeric amounts). - Updates the user's balance and inventory in the database, removing sold items and unequipping them if necessary.
- Sends localized success, cancellation, or error messages, with a 1-minute timeout for interactions.
- Handles errors such as empty inventory, invalid items, or non-sellable items with appropriate messages.
Code Overview
The command:
- Extends the
Commandclass from../../structures/index.js. - Imports
Usersschema and inventory data (ShopItems,ImportantItems,Woods,Minerals,SlimeCategory,Tools). - Filters sellable items (sell price > 0) into
AllItemsfor processing. - Uses the
runmethod to handle both message and slash command inputs, routing tosellAllItems,sellSpecificCategory, orshowSellInterfacebased on input. - Implements
showSellInterfacefor individual item sales with interactive buttons for quantity adjustment and confirmation. - Implements
sellAllItemsandsellSpecificCategoryfor bulk sales, with confirmation embeds and buttons. - Uses
parseQuantityto handle flexible quantity inputs (all,half, numbers). - Updates the database with
Users.updateOneorUsers.findOneAndUpdateto adjust coins and inventory. - Uses a
MessageComponentCollectorfor button interactions, disabling components on timeout (1 minute). - Logs errors and sends localized error messages for issues like database failures or invalid inputs.
Inventory Command
The inventory command displays a user's inventory, organized by categories, with pagination and interactive navigation. This command is available to all users with inventory items.
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.