diff --git a/src/structures/ReactionCollector.js b/src/structures/ReactionCollector.js index e0fa316fc..ee7e75886 100644 --- a/src/structures/ReactionCollector.js +++ b/src/structures/ReactionCollector.js @@ -81,10 +81,11 @@ class ReactionCollector extends Collector { /** * Handles an incoming reaction for possible collection. * @param {MessageReaction} reaction The reaction to possibly collect + * @param {User} user The user that added the reaction * @returns {?Snowflake|string} * @private */ - collect(reaction) { + collect(reaction, user) { /** * Emitted whenever a reaction is collected. * @event ReactionCollector#collect @@ -92,6 +93,19 @@ class ReactionCollector extends Collector { * @param {User} user The user that added the reaction */ if (reaction.message.id !== this.message.id) return null; + + /** + * Emitted whenever a reaction is newly created on a message. Will emit only when a new reaction is + * added to the message, as opposed to {@link Collector#collect} which which will + * be emitted even when a reaction has already been added to the message. + * @event ReactionCollector#create + * @param {MessageReaction} reaction The reaction that was added + * @param {User} user The user that added the reaction + */ + if (reaction.count === 1 && this.filter(reaction, user, this.collected)) { + this.emit('create', reaction, user); + } + return ReactionCollector.key(reaction); } diff --git a/test/reactionCollectorCreated.test.js b/test/reactionCollectorCreated.test.js new file mode 100644 index 000000000..a9220e37b --- /dev/null +++ b/test/reactionCollectorCreated.test.js @@ -0,0 +1,37 @@ +'use strict'; + +const { token, guildId, channelId, messageId } = require('./auth.js'); +const { Client, ReactionCollector } = require('../src'); + +const client = new Client(); + +client.on('ready', async () => { + const guild = client.guilds.cache.get(guildId); + + const channel = guild.channels.cache.get(channelId); + + const message = await channel.messages.fetch(messageId); + + await message.react('🔔'); + // Await message.reactions.removeAll(); + + const collector = new ReactionCollector(message, () => true, { dispose: true }); + + collector.on('collect', () => { + console.log('collected'); + }); + + collector.on('create', () => { + console.log('created'); + }); + + collector.on('remove', () => { + console.log('removed'); + }); + + collector.on('dispose', () => { + console.log('disposed'); + }); +}); + +client.login(token);