feat(ReactionCollector): event create (#4108)

* fix(Typing): setSpeaking public

* feat(ReactionCollector): create event, close #2844

* Revert "fix(Typing): setSpeaking public"

This reverts commit ccc0e0cc76.
This commit is contained in:
Alon Livne
2021-01-27 13:13:15 +02:00
committed by GitHub
parent 640a6633b1
commit 09d1f2f18f
2 changed files with 52 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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);