Get started with Peachy now 🍑
PEACHYPEACHY
Giveaways

Giveaway Reroll

The `giveawayreroll` command allows administrators to reroll ended giveaways to select new winners, useful when original winners don't respond or are ineligible.

Command Details

  • Name: giveawayreroll
  • Aliases: greroll, giveawayredo
  • Category: Giveaway
  • Description: Reroll an ended giveaway to select new winners
  • Usage: P giveawayreroll <message_id>, p giveawayreroll <message_id>, or /giveawayreroll <message_id>
  • Examples:
    • P giveawayreroll 123456789012345678
    • p greroll 987654321098765432
    • /giveawayreroll 112233445566778899
  • Cooldown: 15 seconds
  • Arguments:
    • message_id (required) - ID of the giveaway message to reroll
  • Slash Command: Enabled
  • Permissions:
    • Bot: SendMessages, ViewChannel, EmbedLinks, ReadMessageHistory
    • User: ManageMessages or Administrator
  • Player Requirements: None (no voice, DJ, or active player required)

Functionality

  • Ended Giveaway Detection: Automatically identifies and validates ended giveaways for rerolling.
  • New Winner Selection: Randomly selects new winners from the original participant pool.
  • Duplicate Winner Prevention: Ensures previously selected winners are excluded from reroll selection.
  • Participant Pool Validation: Verifies that sufficient participants remain for reroll selection.
  • Winner Announcement: Announces new winners with clear indication that it's a reroll.
  • Original Giveaway Preservation: Maintains original giveaway data while updating winner information.
  • Multiple Reroll Support: Allows multiple rerolls of the same giveaway if needed.
  • Database Updates: Updates giveaway records with new winner information.
  • Notification System: Notifies new winners about their prize through mentions or direct messages.
  • Historical Tracking: Maintains record of all rerolls for administrative purposes.
  • Error Handling: Provides appropriate feedback for invalid message IDs or ineligible giveaways.
  • Permission Validation: Ensures only authorized users can perform giveaway rerolls.

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.channels.cache.get().messages.fetch() to retrieve the original giveaway message by ID.
  • Giveaway status validation to ensure the target giveaway has ended and is eligible for reroll.
  • message.reactions.cache.get('🎉').users.fetch() to retrieve original participants from reactions.
  • Winner exclusion algorithms to prevent selecting previous winners in the reroll process.
  • Random selection logic using Math.random() and array manipulation for fair winner selection.
  • Database queries to update giveaway records with new winner information and reroll history.
  • Enhanced embed creation showing reroll status and newly selected winners.
  • Error handling for invalid message IDs, non-existent giveaways, or insufficient participants.
  • Permission checking to ensure user authorization for performing giveaway rerolls.
  • Winner notification system with automatic mentions and prize distribution information.
  • Administrative logging of reroll actions for moderation and audit trail purposes.
  • Integration with existing giveaway systems for seamless prize distribution to new winners.