Get started with Peachy now πŸ‘
PEACHYPEACHY
Fun

Guess Number

The `guessnumber` command allows users to play a number-guessing game in a Discord server, attempting to guess a number between 1 and 100. It can be triggered using the slash command `/` or prefix commands.

Command Details

  • Name: guessnumber
  • Aliases: gn
  • Category: Fun
  • Description: Challenges users to guess a random number between 1 and 100, with a cost of 1000 coins to play.
  • Usage: P guessnumber, p guessnumber, or /guessnumber
  • Examples:
    • P guessnumber
    • p guessnumber
    • /guessnumber
  • Cooldown: 10 seconds
  • Arguments: None
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks, AddReactions
    • User: None
  • Player Requirements: User must have at least 1000 coins in their balance.

Functionality

  • Checks if the user has at least 1000 coins; if not, displays an error: "You don't have enough coins to play this game."
  • Deducts 1000 coins from the user’s balance to start the game and generates a random number between 1 and 100.
  • Users have 3 attempts (hearts) to guess the number, with a 30-second time limit to respond.
  • On each guess:
    • If correct, awards 5000–10000 coins and 30–80 XP, displays a success embed with a random congratulatory emoji, and ends the game.
    • If incorrect, deducts one heart and provides hints:
      • After the first incorrect guess: Indicates if the guess is too high or too low.
      • After the second incorrect guess: Provides a range (e.g., between 45 and 65).
      • After the third incorrect guess: Ends the game, revealing the correct number.
  • If the time limit expires, a timeout message is shown.
  • Uses embeds for all messages, including the user’s avatar, localized text, and dynamic colors (success, danger, warning).
  • Supports both prefix-based (P or p) and slash command (/) inputs.

Code Overview

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

  • client.embed() to create formatted embeds for game status, results, and errors.
  • A message collector to handle user guesses, filtering for valid numbers (1–100) from the invoking user.
  • A database (via client.utils.getUser) to manage user balance and XP.
  • Language localization for messages and emojis (via language.locales for general and game-specific messages).
  • Error handling for insufficient balance and invalid guesses.
  • Randomization for the target number, rewards, and hints to enhance replayability.