diff --git a/README.md b/README.md index 86260034..ca40df38 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,8 @@ client.on('messageCreate', (message) => { }); ``` +- **noWinnerMessage**: Sent in the channel if there is no valid winner for the giveaway. + ### Fetch giveaways ```js diff --git a/src/Constants.js b/src/Constants.js index a886a8ee..e215e335 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -10,7 +10,7 @@ const Discord = require('discord.js'); * @property {string} [timeRemaining='Time remaining: **{duration}**'] Displayed below "inviteToParticipate" in the giveaway embed. "{duration}" will be replaced automatically with the time remaining. * @property {string} [winMessage='Congratulations, {winners}! You won **{prize}**!\n{messageURL}'] Sent in the channel when the giveaway is ended. * @property {string|EmbedFooterObject} [embedFooter='Powered by the discord-giveaways package'] The footer of the giveaway embed. - * @property {string} [noWinner='Giveaway cancelled, no valid participations.'] Sent in the channel if there is no valid winner for the giveaway. + * @property {string} [noWinner='Giveaway cancelled, no valid participations.'] Displayed in the giveaway embed when there is no valid winner for the giveaway. * @property {string} [winners='winner(s)'] Displayed next to the embed footer, used to display the number of winners of the giveaways. * @property {string} [endedAt='Ended at'] Displayed next to the embed footer, used to display the giveaway end date. * @property {string} [hostedBy='Hosted by: {user}'] Below the "inviteToParticipate" message, in the description of the embed. diff --git a/src/Giveaway.js b/src/Giveaway.js index addcab46..6a5fac80 100644 --- a/src/Giveaway.js +++ b/src/Giveaway.js @@ -505,9 +505,10 @@ class Giveaway extends EventEmitter { /** * Ends the giveaway. + * @param {string} [noWinnerMessage=null] Sent in the channel if there is no valid winner for the giveaway. * @returns {Promise} The winner(s). */ - end() { + end(noWinnerMessage = null) { return new Promise(async (resolve, reject) => { if (this.ended) return reject('Giveaway with message Id ' + this.messageId + ' is already ended'); this.ended = true; @@ -560,6 +561,7 @@ class Giveaway extends EventEmitter { } resolve(winners); } else { + if (typeof noWinnerMessage === 'string') this.channel.send(noWinnerMessage); const embed = this.manager.generateNoValidParticipantsEndEmbed(this); this.message.edit({ content: this.messages.giveawayEnded, embeds: [embed] }).catch(() => {}); resolve([]); diff --git a/src/Manager.js b/src/Manager.js index 72ee23d3..9999bdf1 100644 --- a/src/Manager.js +++ b/src/Manager.js @@ -160,19 +160,20 @@ class GiveawaysManager extends EventEmitter { /** * Ends a giveaway. This method is automatically called when a giveaway ends. - * @param {Discord.Snowflake} messageId The message Id of the giveaway + * @param {Discord.Snowflake} messageID The message ID of the giveaway + * @param {string} [noWinnerMessage=null] Sent in the channel if there is no valid winner for the giveaway. * @returns {Promise} The winners * * @example * manager.end('664900661003157510'); */ - end(messageId) { + end(messageID, noWinnerMessage = null) { return new Promise(async (resolve, reject) => { const giveaway = this.giveaways.find((g) => g.messageId === messageId); if (!giveaway) return reject('No giveaway found with message Id ' + messageId + '.'); giveaway - .end() + .end(noWinnerMessage) .then((winners) => { this.emit('giveawayEnded', giveaway, winners); resolve(winners); diff --git a/typings/index.d.ts b/typings/index.d.ts index 0df1aef0..03d8372b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -27,7 +27,7 @@ declare module 'discord-giveaways' { public delete(messageId: Snowflake, doNotDeleteMessage?: boolean): Promise; public deleteGiveaway(messageId: Snowflake): Promise; public edit(messageId: Snowflake, options: GiveawayEditOptions): Promise; - public end(messageId: Snowflake): Promise; + public end(messageID: Snowflake, noWinnerMessage?: string): Promise; public reroll(messageId: Snowflake, options?: GiveawayRerollOptions): Promise; public start(channel: TextChannel | NewsChannel | ThreadChannel, options: GiveawayStartOptions): Promise; public pause(messageId: Snowflake, options: PauseOptions): Promise; @@ -160,7 +160,7 @@ declare module 'discord-giveaways' { public exemptMembers(member: GuildMember): Promise; public edit(options: GiveawayEditOptions): Promise; - public end(): Promise; + public end(noWinnerMessage?: string): Promise; public fetchMessage(): Promise; public reroll(options?: GiveawayRerollOptions): Promise; public roll(winnerCount?: number): Promise;