Get started with Peachy now 🍑
PEACHYPEACHY
Bank

Withdraw

The `withdraw` command allows users to transfer money from their bank account to their wallet for spending and transactions.

Command Details

  • Name: withdraw
  • Aliases: with, wd
  • Category: Bank
  • Description: Withdraw money from your bank account to your wallet
  • Usage: P withdraw <amount>, p withdraw <amount>, or /withdraw <amount>
  • Examples:
    • P withdraw 1000
    • p with all
    • /withdraw 25000
  • Cooldown: 3 seconds
  • Arguments: amount (required) - The amount to withdraw or "all" for entire bank balance
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks
    • User: None
  • Player Requirements: None (no voice, DJ, or active player required)

Functionality

  • Bank to Wallet Transfer: Moves coins from secure bank storage to accessible wallet for spending.
  • Flexible Amount Input: Accepts specific amounts or "all" keyword for complete bank withdrawal.
  • Balance Validation: Ensures users have sufficient bank funds before processing withdrawals.
  • Instant Processing: Immediately updates both bank and wallet balances in real-time.
  • Transaction Confirmation: Provides clear confirmation with before/after balance display.
  • Input Sanitization: Handles various input formats including commas and multipliers.
  • Error Prevention: Prevents withdrawals of more money than available in bank.
  • Zero Validation: Prevents withdrawals of zero or negative amounts with appropriate messaging.
  • Database Updates: Securely updates user financial records with transaction details.
  • Transaction History: May log withdrawal transactions for user financial tracking.
  • Spending Preparation: Makes money available for gambling, shopping, and other activities.
  • Real-Time Updates: Immediately reflects changes in user's financial accessibility.

Code Overview

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

  • client.utils.getUser() for retrieving current user financial data from the database.
  • Amount parsing and validation including "all" keyword handling and number conversion.
  • client.utils.formatNumber() for displaying transaction amounts in readable formats.
  • Balance validation ensuring sufficient bank funds before processing withdrawals.
  • Database transaction updates modifying both balance.bank.coin and balance.wallet.coin values.
  • client.embed() creation with transaction confirmation and updated balance display.
  • Input sanitization handling commas, multipliers (k, m, b), and various number formats.
  • Error handling for insufficient funds, invalid amounts, or database connection issues.
  • Transaction success confirmation with before/after balance comparisons.
  • Integration with the bot's economy system for consistent financial data management.
  • Withdrawn money goes to your wallet for immediate use
  • There may be daily withdrawal limits depending on server settings
  • Money in your wallet may be at risk in certain server games/activities

Permissions

  • No special permissions required
  • Must have money in bank to withdraw