Giveaways
Giveaway Shop Item
The `gshopitem` command allows users to create specialized giveaways featuring shop items like food, drinks, themes, milk, and rings with automatic inventory management.
Command Details
- Name: gshopitem
- Aliases: gs
- Category: Giveaway
- Description: Start a shop item giveaway for food, drink, or themes, milk, ring in the shop
- Usage:
P gshopitem <duration> <winners> <type> <itemID> <amount> <image> <thumbnail> <autoadd> [host] [channel]
,p gshopitem <duration> <winners> <type> <itemID> <amount> <image> <thumbnail> <autoadd> [host] [channel]
, or/gshopitem <duration> <winners> <type> <itemID> <amount> <image> <thumbnail> <autoadd>
- Examples:
P gshopitem 1h 1 food f01 5 true
p gshopitem 2h 3 drink d01 false @User #channel
/gshopitem 6h 2 theme t01 1
- Cooldown: Not specified
- Arguments:
- duration (required) - Duration of the giveaway
- winners (required) - Number of winners
- type (required) - The giveaway type (food, drink, theme, milk, ring)
- itemID (required) - The item ID from the shop
- amount (required) - The amount of items to give away
- image (optional) - Image URL for the giveaway
- autoadd (optional) - Automatically add item winners (true/false) - Owner only
- Slash Command: Enabled
- Permissions:
- Bot: SendMessages, ViewChannel, EmbedLinks
- User: None (any user can create shop item giveaways)
- Player Requirements: None (no voice, DJ, or active player required)
Functionality
- Multi-Category Shop Items: Supports food, drink, theme, milk, and ring categories from the bot's shop system.
- Item Type Validation: Validates item categories and ensures items exist in the specified type.
- Case-Insensitive Item Search: Finds items using case-insensitive ID matching for user convenience.
- Owner-Only Auto-Add: Automatic item distribution feature restricted to bot owners only.
- Visual Item Display: Shows item emoji thumbnails using
client.utils.emojiToImage()
conversion. - Flexible Amount System: Allows specifying custom amounts of items to give away per winner.
- Button-Based Entry: Uses interactive buttons for joining and viewing participants.
- Image Attachment Support: Optional image attachments for enhanced giveaway visuals.
- Comprehensive Validation: Validates duration, winner count, item ID, and amount inputs.
- Database Integration: Stores detailed giveaway information in dedicated shop item schema.
- Error Recovery: Provides detailed error messages for invalid inputs or missing items.
- Permission-Based Features: Restricts advanced features like auto-add to authorized users.
- Real-Time Updates: Dynamic embed updates with participant counts and countdown timers.
- Multi-Source Item Loading: Combines regular shop items with important items for comprehensive selection.
Code Overview
The command is built using a Command
class structure and handles both message-based and interaction-based (slash command) inputs. It uses:
globalConfig.owners.includes()
for bot owner validation and auto-add permission checking.ms()
library for duration parsing andDate.now() + duration
for end time calculations.items.concat(importantItems).filter()
to combine shop items and important items by category type.- Case-insensitive item finding using
item.id.toLowerCase() === itemID.toLowerCase()
matching. ctx.interaction.deferReply()
andctx.sendDeferMessage()
for handling processing delays.- Comprehensive input validation for duration, winners, item ID, and amount parameters.
client.utils.emojiToImage()
for converting item emojis to thumbnail images.client.utils.formatNumber()
for displaying formatted item amounts in embeds.- Button-based interaction system using
client.utils.fullOptionButton()
for join and participants. client.utils.createButtonRow()
for organizing interactive components.GiveawayShopItemSchema.create()
for database persistence with detailed giveaway information.- Error handling with appropriate user feedback for invalid categories, missing items, or permission issues.
- Owner-only auto-add functionality with permission validation and error messaging.
- Image attachment support through Discord interaction options and embed integration.
- Real-time countdown display using Discord timestamp formatting (
<t:${formattedDuration}:R>
).
Giveaway
The `gstart` command allows users to create interactive coin giveaways with customizable descriptions, prizes, duration, and winner selection with optional autopay functionality.
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.