Get started with Peachy now 🍑
PEACHYPEACHY
Growing A Tree

View

The `tree` command allows users to view or start a virtual tree in a Discord server. It can be triggered using the slash command `/` or prefix commands.

Command Details

  • Name: tree
  • Aliases: None
  • Category: Games
  • Description: Displays a user's virtual tree or prompts to create one if none exists.
  • Usage: P tree, p tree, or /tree
  • Examples:
    • P tree
    • p tree
    • /tree
  • Cooldown: 5 seconds
  • Arguments: None
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks
    • User: None
  • Player Requirements: None (no voice, DJ, or active player required)

Functionality

  • If the user has no tree, a modal prompts them to name a new tree (max 32 characters, required).
  • If a tree exists, the command displays:
    • An embed with the tree’s name, height, and water count.
    • A dynamically generated tree image (via generateTreeCanvas).
    • A "Water Tree" button to interact with the tree (1-minute cooldown per water action).
  • The button increases the tree’s height by 1 ft, adds 10 XP, increments the water count, and updates the last watered timestamp.
  • The embed and image update after watering, reflecting the new tree stats.
  • The button disables after 5 minutes of inactivity (collector timeout).
  • Supports both prefix-based (P or p) and slash command (/) inputs.
  • Includes a cooldown check to prevent watering more than once per minute, with a user-friendly time-remaining message.

Code Overview

The command is built using a Command class structure and handles both message-based and interaction-based inputs. It uses:

  • Tree schema to store and retrieve tree data (name, height, XP, water count, last watered).
  • generateTreeCanvas to create a visual representation of the tree based on its height.
  • ModalBuilder, TextInputBuilder, and ActionRowBuilder for creating a modal to name new trees.
  • ButtonBuilder and AttachmentBuilder for interactive buttons and image attachments.
  • A button collector to handle "Water Tree" interactions, with a 5-minute timeout and user-specific filtering.
  • Language localization for messages (via language.locales) and global emojis (via globalEmoji).
  • Error handling for cases where no tree exists or watering is on cooldown.