Get started with Peachy now 🍑
PEACHYPEACHY
Inventory

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.

Command Details

  • Name: use
  • Aliases: None
  • Category: Inventory
  • Description: Use a theme, wallpaper, color, tool, or potion item to customize your profile or apply effects
  • Usage: use <itemId>
  • Examples:
    • use t01
    • use w01
    • use p01
  • Cooldown: 5 seconds
  • Arguments: Yes (item ID)
  • Slash Command: Disabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks
    • User: None
  • Player Requirements: Must have the specified item in inventory

Functionality

  • Retrieves the user's inventory from the Users schema and checks for the specified item in ImportantItems, ShopItems, Wallpapers, Themes, Colors, Tools, or potions.
  • Supports using items of types: theme, special theme, wallpaper, color, tool, and potion.
  • For themes, wallpapers, and colors, equips the item, removes it from inventory (decrementing quantity or removing if quantity is 1), and returns any previously equipped item to inventory.
  • For tools, checks if already equipped; if so, prompts for confirmation to change, otherwise equips directly and decrements inventory.
  • For potions, applies a luck buff with dynamic duration and boost, storing it in a client.luckBuffs Map, and decrements inventory.
  • Validates item ownership and usability, preventing use of non-usable items or already equipped items.
  • Updates the database (Users.updateOne) to reflect changes in inventory, equip, and preferences.
  • Sends localized success or error messages with embeds, including item details and effect descriptions (e.g., luck boost percentage and duration).

Code Overview

The command:

  • Extends the Command class from ../../structures/index.js.
  • Imports Users schema and inventory data (ImportantItems, ShopItems, filtered into Themes, Wallpapers, Colors, Tools).
  • Uses the run method to handle both message and interaction inputs, validating the item ID and user inventory.
  • Handles different item types (theme, special theme, wallpaper, color, tool, potion) with specific logic for each.
  • For themes, wallpapers, and colors, manages equipment swaps and inventory updates, ensuring only one item of each type is equipped.
  • For tools, uses interactive buttons (ButtonBuilder, ActionRowBuilder) for confirmation if a tool is already equipped.
  • For potions, applies luck buffs to a client-side Map and logs the action for debugging.
  • Updates the database with Users.updateOne for inventory and equipment changes.
  • Sends localized embeds for success or errors, handling cases like invalid items, non-usable items, or database errors.