Get started with Peachy now 🍑
PEACHYPEACHY
Gambling

Coinflip

The `coinflip` command allows users to flip a coin and bet on either Peach or Goma side. It can be triggered using the prefixes `P`, `p`, or the slash command `/`.

Command Details

  • Name: coinflip
  • Aliases: flip, cf
  • Category: Gambling
  • Description: Flip a coin and let's see who's the lucky one!
  • Usage: P coinflip <amount> <choice>, p coinflip <amount> <choice>, or /coinflip <amount> <choice>
  • Examples:
    • P coinflip 100 peach
    • p coinflip 100 goma
    • /coinflip 100 peach
  • Cooldown: 3 seconds
  • Arguments: amount (required), choice (required)
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks
    • User: None
  • Player Requirements: None (no voice, DJ, or active player required)

Functionality

  • Simple coin flip gambling game with Peach and Goma themed sides.
  • Validates that users aren't already in active games (KlaKlouk or MultiTransfer).
  • Accepts betting amounts with special keywords like "all" or "half".
  • Maximum bet limit of 250,000 coins per game.
  • Choice validation for "peach"/"p" or "goma"/"g" options.
  • Animated coin flip with a 2-second delay for suspense.
  • Random outcome generation with 50/50 probability.
  • Visual feedback with appropriate coin side thumbnails.
  • Win condition: Double the bet amount on correct guess.
  • Lose condition: Forfeit the bet amount on incorrect guess.
  • Real-time balance updates in the database.
  • Displays game progress and final results with formatted coin amounts.
  • Supports both prefix-based (P or p) and slash command (/) inputs.
  • Handles errors with appropriate error messages.

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() to fetch and validate user data from the database.
  • client.utils.getRandomNumber(0, 1) to generate random coin flip results.
  • client.utils.formatNumber() to display formatted coin amounts.
  • client.utils.emojiToImage() to convert coin flip emojis into thumbnail images.
  • Choice validation and normalization for user inputs.
  • Animated embed updates with timed delays for dramatic effect.
  • Balance management with immediate updates based on game outcome.
  • Themed visual elements using Peach and Goma coin sides.
  • Language localization for all game messages and results.
  • Error handling for invalid choices and database operations.
  • Game state tracking with progress and completion footers.