Transfer
The `transfer` command allows users to send money directly to other users' accounts with transaction confirmation and balance updates.
Command Details
- Name: transfer
- Aliases: give, send, pay
- Category: Bank
- Description: Transfer money from your account to another user's account
- Usage:
P transfer @user <amount>
,p transfer @user <amount>
, or/transfer @user <amount>
- Examples:
P transfer @JohnDoe 500
p give @friend 1000
/transfer @user 25000
- Cooldown: 5 seconds
- Arguments:
- user (required) - The user you want to transfer money to
- amount (required) - The amount to transfer
- Slash Command: Enabled
- Permissions:
- Bot: SendMessages, ViewChannel, EmbedLinks
- User: None
- Player Requirements: None (no voice, DJ, or active player required)
Functionality
- User-to-User Transfers: Safely sends money between user accounts with transaction verification.
- Multi-Source Withdrawal: Draws from wallet first, then bank if needed to complete transfers.
- Recipient Validation: Ensures target users exist and have valid economy profiles.
- Self-Transfer Prevention: Prevents users from transferring money to themselves.
- Balance Verification: Confirms sender has sufficient funds before processing transfers.
- Transaction Confirmation: Provides detailed confirmation to both sender and recipient.
- Real-Time Updates: Immediately updates both users' balances in the database.
- Transfer Limits: May enforce daily or per-transaction transfer limits for security.
- Fee System: Optional transfer fees depending on server configuration.
- Input Sanitization: Handles various amount formats including multipliers and commas.
- Error Recovery: Comprehensive error handling for failed transfers with balance protection.
- Social Economy: Enables gift-giving, payments, and social financial interactions.
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 both sender and recipient financial data. -
User validation ensuring target users exist and preventing self-transfers.
-
Multi-source balance checking across wallet and bank accounts for sufficient funds.
-
Amount parsing and validation with support for various input formats and multipliers.
-
Transaction processing with atomic database updates for both sender and recipient.
-
client.utils.formatNumber()
for displaying transfer amounts in readable formats. -
client.embed()
creation with transfer confirmation and updated balance information. -
Error handling for insufficient funds, invalid recipients, or database transaction failures.
-
Optional transfer fee calculation and deduction based on server settings.
-
Transaction logging and history tracking for financial audit purposes.
-
Balance rollback mechanisms in case of partial transaction failures.
-
Integration with the bot's economy system for consistent financial data management.
-
No special permissions required
-
Both users must be registered in the banking system
-
Recipient must accept transfers (if server has this setting enabled)