Class: GiveawaysManager


GiveawaysManager(client, optionsopt, initopt)

Giveaways Manager

Constructor

new GiveawaysManager(client, optionsopt, initopt)

Parameters:
Name Type Attributes Default Description
client Discord.Client

The Discord Client

options GiveawaysManagerOptions <optional>

The manager options

init boolean <optional>
true

If the manager should start automatically. If set to "false", for example to create a delay, the manager can be started manually with "manager._init()".


Members

client :Discord.Client

The Discord Client

Type:
  • Discord.Client

giveaways :Array.<Giveaway>

The giveaways managed by this manager

Type:

options :GiveawaysManagerOptions

The manager options

Type:

ready :boolean

Whether the manager is ready

Type:
  • boolean

Methods

delete(messageId, doNotDeleteMessageopt) → {Promise.<Giveaway>}

Deletes a giveaway. It will delete the message and all the giveaway data.

Parameters:
Name Type Attributes Default Description
messageId Discord.Snowflake

The message Id of the giveaway

doNotDeleteMessage boolean <optional>
false

Whether the giveaway message shouldn't be deleted

Returns:

(async) deleteGiveaway(messageId) → {Promise.<boolean>}

Delete a giveaway from the database

Parameters:
Name Type Description
messageId Discord.Snowflake

The message Id of the giveaway to delete

Returns:
  • Type: Promise.<boolean>

edit(messageId, optionsopt) → {Promise.<Giveaway>}

Edits a giveaway. The modifications will be applicated when the giveaway will be updated.

Parameters:
Name Type Attributes Default Description
messageId Discord.Snowflake

The message Id of the giveaway to edit

options GiveawayEditOptions <optional>
{}

The edit options

Returns:

The edited giveaway

Example
manager.edit('664900661003157510', {
     newWinnerCount: 2,
     newPrize: 'Something new!',
     addTime: -10000 // The giveaway will end 10 seconds earlier
});

end(messageId, noWinnerMessageopt) → {Promise.<Array.<Discord.GuildMember>>}

Ends a giveaway. This method is automatically called when a giveaway ends.

Parameters:
Name Type Attributes Default Description
messageId Discord.Snowflake

The message id of the giveaway

noWinnerMessage string | MessageObject <optional>
null

Sent in the channel if there is no valid winner for the giveaway.

Returns:

The winners

  • Type: Promise.<Array.<Discord.GuildMember>>
Example
manager.end('664900661003157510');

generateEndEmbed(giveaway, winners) → {Discord.EmbedBuilder}

Generate an embed displayed when a giveaway is ended (with the winners list)

Parameters:
Name Type Description
giveaway Giveaway

The giveaway the embed needs to be generated for

winners Array.<Discord.GuildMember>

The giveaway winners

Returns:

The generated embed

  • Type: Discord.EmbedBuilder

generateMainEmbed(giveaway, lastChanceEnabledopt) → {Discord.EmbedBuilder}

Generate an embed displayed when a giveaway is running (with the remaining time)

Parameters:
Name Type Attributes Default Description
giveaway Giveaway

The giveaway the embed needs to be generated for

lastChanceEnabled boolean <optional>
false

Whether or not to include the last chance text

Returns:

The generated embed

  • Type: Discord.EmbedBuilder

generateNoValidParticipantsEndEmbed(giveaway) → {Discord.EmbedBuilder}

Generate an embed displayed when a giveaway is ended and when there is no valid participant

Parameters:
Name Type Description
giveaway Giveaway

The giveaway the embed needs to be generated for

Returns:

The generated embed

  • Type: Discord.EmbedBuilder

pause(messageId, optionsopt) → {Promise.<Giveaway>}

Pauses a giveaway.

Parameters:
Name Type Attributes Default Description
messageId Discord.Snowflake

The message Id of the giveaway to pause.

options PauseOptions <optional>
giveaway.pauseOptions

The pause options.

Returns:

The paused giveaway.

Example
manager.pause('664900661003157510');

reroll(messageId, optionsopt) → {Promise.<Array.<Discord.GuildMember>>}

Choose new winner(s) for the giveaway

Parameters:
Name Type Attributes Description
messageId Discord.Snowflake

The message Id of the giveaway to reroll

options GiveawayRerollOptions <optional>

The reroll options

Returns:

The new winners

  • Type: Promise.<Array.<Discord.GuildMember>>
Example
manager.reroll('664900661003157510');

start(channel, options) → {Promise.<Giveaway>}

Starts a new giveaway

Parameters:
Name Type Description
channel Discord.GuildTextBasedChannel

The channel in which the giveaway will be created

options GiveawayStartOptions

The options for the giveaway

Returns:

The created giveaway.

Example
manager.start(interaction.channel, {
     prize: 'Free Steam Key',
     // Giveaway will last 10 seconds
     duration: 10000,
     // One winner
     winnerCount: 1,
     // Limit the giveaway to members who have the "Nitro Boost" role
     exemptMembers: (member) => !member.roles.cache.some((r) => r.name === 'Nitro Boost')
});

unpause(messageId) → {Promise.<Giveaway>}

Unpauses a giveaway.

Parameters:
Name Type Description
messageId Discord.Snowflake

The message Id of the giveaway to unpause.

Returns:

The unpaused giveaway.

Example
manager.unpause('664900661003157510');

Events

endedGiveawayReactionAdded

Emitted when someone reacted to a ended giveaway.

Parameters:
Name Type Description
giveaway Giveaway

The giveaway instance

member Discord.GuildMember

The member who reacted to the ended giveaway

reaction Discord.MessageReaction

The reaction to enter the giveaway

Example
// This can be used to prevent new participants when giveaways get rerolled
manager.on('endedGiveawayReactionAdded', (giveaway, member, reaction) => {
     return reaction.users.remove(member.user);
});

giveawayDeleted

Emitted when a giveaway was deleted.

Parameters:
Name Type Description
giveaway Giveaway

The giveaway instance

Example
// This can be used to add logs
manager.on('giveawayDeleted', (giveaway) => {
     console.log('Giveaway with message Id ' + giveaway.messageId + ' was deleted.')
});

giveawayEnded

Emitted when a giveaway ended.

Parameters:
Name Type Description
giveaway Giveaway

The giveaway instance

winners Array.<Discord.GuildMember>

The giveaway winners

Example
// This can be used to add features such as a congratulatory message in DM
manager.on('giveawayEnded', (giveaway, winners) => {
     winners.forEach((member) => {
         member.send('Congratulations, ' + member.user.username + ', you won: ' + giveaway.prize);
     });
});

giveawayReactionAdded

Emitted when someone entered a giveaway.

Parameters:
Name Type Description
giveaway Giveaway

The giveaway instance

member Discord.GuildMember

The member who entered the giveaway

reaction Discord.MessageReaction

The reaction to enter the giveaway

Example
// This can be used to add features such as removing reactions of members when they do not have a specific role (= giveaway requirements)
// Best used with the "exemptMembers" property of the giveaways
manager.on('giveawayReactionAdded', (giveaway, member, reaction) => {
    if (!member.roles.cache.get('123456789')) {
         reaction.users.remove(member.user);
         member.send('You must have this role to participate in the giveaway: Staff');
    }
});

giveawayReactionRemoved

Emitted when someone removed their reaction to a giveaway.

Parameters:
Name Type Description
giveaway Giveaway

The giveaway instance

member Discord.GuildMember

The member who remove their reaction giveaway

reaction Discord.MessageReaction

The reaction to enter the giveaway

Example
// This can be used to add features such as a member-left-giveaway message per DM
manager.on('giveawayReactionRemoved', (giveaway, member, reaction) => {
     return member.send('That\'s sad, you won\'t be able to win the super cookie!');
});

giveawayRerolled

Emitted when a giveaway was rerolled.

Parameters:
Name Type Description
giveaway Giveaway

The giveaway instance

winners Array.<Discord.GuildMember>

The winners of the giveaway

Example
// This can be used to add features such as a congratulatory message per DM
manager.on('giveawayRerolled', (giveaway, winners) => {
     winners.forEach((member) => {
         member.send('Congratulations, ' + member.user.username + ', you won: ' + giveaway.prize);
     });
});