Get started with Peachy now 🍑
PEACHYPEACHY
Work

Police

The police command allows players with the Police job to catch thieves who have successfully robbed another user. It includes success and failure outcomes with rewards and penalties.

Command Details

  • Name: police
  • Aliases: catch, catchthief
  • Category: Work
  • Description: Police can catch thieves who have successfully robbed someone.
  • Usage:
    • police <user>
  • Examples:
    • police @username
  • Cooldown: 10 seconds
  • Arguments: Required (target user)
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks
    • User: None
  • Player Requirements:
    • User must have Police job and be approved.
    • Target must have recently robbed someone successfully.

Functionality

  • Accepts one argument or slash option: target user (the thief to catch).
  • Validation:
    • Target must be mentioned and cannot be the same as the command user.
    • Both users must be registered.
    • Command user must have position = police and status = approved.
    • Target must have a pending robbery record (rob = true and robAmount > 0).
  • Catch Mechanics:
    • 80% chance of success (using chance.bool()).
  • Success Outcome:
    • Thief loses the stolen amount.
    • Police earns 120% of the stolen amount as reward.
    • Thief's rob and robAmount reset.
  • Failure Outcome:
    • Police pays a penalty of 1% of their current balance.
  • Updates database for both players.
  • Sends localized embed message for success or failure with details:
    • Amount recovered
    • Reward or penalty
    • Usernames and requested by footer.

Code Overview

The command:

  • Extends the Command class from ../../structures/index.js.
  • Uses ctx.isInteraction for slash command input.
  • Fetches both the police officer and target user from Users schema.
  • Validates roles and robbery conditions.
  • Calculates reward or penalty:
    • Success → reward = robAmount * 1.2
    • Failure → penalty = police.balance.coin * 0.01
  • Uses helper utilities:
    • client.utils.getRandomElement() for police emoji.
    • client.utils.formatNumber() for amounts.
  • Sends response as an embed with:
    • Random police emoji thumbnail
    • Localized message templates

Example Embed (Success)