Get started with Peachy now 🍑
PEACHYPEACHY
Growing A Tree

Rename

The `rename-tree` command allows users to rename their virtual tree in a Discord server. It is triggered exclusively using the slash command `/`.

Command Details

  • Name: rename-tree
  • Aliases: None
  • Category: Games
  • Description: Renames a user's existing virtual tree.
  • Usage: /rename-tree
  • Examples:
    • /rename-tree
  • Cooldown: 5 seconds
  • Arguments: None (modal input for new tree name)
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks
    • User: None
  • Player Requirements: None (no voice, DJ, or active player required)

Functionality

  • The command is exclusive to slash command input (/rename-tree) and does not support prefix-based triggers.
  • Checks if the user has an existing tree in the database using the Tree schema.
  • If no tree is found, an ephemeral error message is displayed: "❌ You don't have a tree yet. Use /tree to start one!"
  • If a tree exists, a modal is shown with a text input field for the new tree name (max 32 characters, required).
  • The modal is user-specific, using a unique custom ID tied to the user's ID.
  • Error handling ensures the command fails gracefully if invoked outside of a slash command context, displaying: "⚠️ This command only works with slash commands right now."

Code Overview

The command is built using a Command class structure and handles slash command interactions. It uses:

  • ModalBuilder, TextInputBuilder, and ActionRowBuilder from discord.js to create an interactive modal.
  • Tree schema to query the database for the user's tree.
  • Ephemeral messaging (flags: 64) for error responses to keep channels clean.
  • Language localization support (via the language parameter, though not implemented in the provided code).
  • Error handling for cases where no tree exists or the command is invoked incorrectly.