Creates a new GiveawayManager instance.
The Discord.js client instance that will be used for bot operations
The storage adapter for persisting giveaway data (JSONAdapter, SequelizeAdapter, etc.)
Configuration options for the giveaway manager
Configuration options for the GiveawayManager instance.
These options control the global behavior of the giveaway manager, including reaction emoji, bot participation, and localization.
The emoji reaction that users will use to enter giveaways
Whether bot accounts are allowed to participate and win giveaways
Optional
language?: "en" | "cs"Language for giveaway messages and UI text
Readonly
eventsEvent emitter for giveaway-related events.
This property provides access to all giveaway events that you can listen to for custom handling.
Available events:
giveawayStarted
: Emitted when a new giveaway is startedgiveawayEnded
: Emitted when a giveaway naturally endsgiveawayRerolled
: Emitted when a giveaway is rerolledgiveawayEdited
: Emitted when a giveaway is editedreactionAdded
: Emitted when someone reacts to a giveawayrequirementsFailed
: Emitted when a user fails entry requirementsrequirementsPassed
: Emitted when a user passes entry requirements// Listen for giveaway events
giveawayManager.events.on('giveawayStarted', (giveaway) => {
console.log(`Giveaway started: ${giveaway.prize}`);
});
giveawayManager.events.on('giveawayEnded', (giveaway, winners) => {
console.log(`Giveaway ended! Winners: ${winners.join(', ')}`);
});
giveawayManager.events.on('requirementsFailed', (giveaway, user, reason) => {
console.log(`${user.username} failed requirements: ${reason}`);
});
Starts a new giveaway with the specified options.
This method creates a new giveaway, sends an embed message to the specified channel, adds the reaction emoji, sets up automatic ending, and begins collecting reactions.
The configuration for the giveaway
Configuration options for creating a new giveaway.
This interface defines all the parameters needed to start a giveaway, including duration, prize details, and entry requirements.
Discord channel ID where the giveaway will be posted
Description of the prize being offered
Number of winners to select when the giveaway ends
Duration of the giveaway in milliseconds
Optional
requirements?: GiveawayRequirementsOptional entry requirements that participants must meet
A Promise that resolves to the created GiveawayData object
Internal
Ends a giveaway and selects winners.
This method retrieves all reactions from the giveaway message, filters out bots (if configured), selects random winners, updates the embed to show the results, and emits appropriate events.
The unique identifier of the giveaway to end
Whether this is a reroll operation (affects which event is emitted)
A Promise that resolves when the giveaway has been ended
Edits an existing giveaway's details.
This method allows you to modify the prize, winner count, and requirements of an active giveaway. The giveaway message embed will be updated to reflect the changes, and the updated data will be saved to storage.
The unique identifier of the giveaway to edit
The new giveaway options (prize, winnerCount, requirements)
Configuration options for creating a new giveaway.
This interface defines all the parameters needed to start a giveaway, including duration, prize details, and entry requirements.
Discord channel ID where the giveaway will be posted
Description of the prize being offered
Number of winners to select when the giveaway ends
Duration of the giveaway in milliseconds
Optional
requirements?: GiveawayRequirementsOptional entry requirements that participants must meet
A Promise that resolves when the giveaway has been updated
// Edit a giveaway to change the prize and add requirements
await giveawayManager.edit('abc123def', {
channelId: '123456789', // Must match original
prize: 'Discord Nitro + $50 Gift Card', // Updated prize
winnerCount: 3, // Increased winner count
duration: 0, // Not used in editing
requirements: {
requiredRoles: ['987654321', '876543210'] // Added requirements
}
});
Internal
Restores timeouts and reaction collectors for all active giveaways.
This method is essential for maintaining giveaway functionality after bot restarts. It retrieves all active giveaways from storage and re-establishes their timeouts and reaction collectors. This method is automatically called during construction.
A Promise that resolves when all timeouts have been restored
Rerolls the winners of an active giveaway.
This method allows you to select new winners for a giveaway without ending it permanently. It performs the same winner selection process as the end method but emits a 'giveawayRerolled' event instead of 'giveawayEnded'.
The unique identifier of the giveaway to reroll
A Promise that resolves when the reroll has been completed
GiveawayManager represents a comprehensive manager for creating and managing Discord giveaways.
Example