mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
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:
@@ -81,10 +81,11 @@ class ReactionCollector extends Collector {
|
|||||||
/**
|
/**
|
||||||
* Handles an incoming reaction for possible collection.
|
* Handles an incoming reaction for possible collection.
|
||||||
* @param {MessageReaction} reaction The reaction to possibly collect
|
* @param {MessageReaction} reaction The reaction to possibly collect
|
||||||
|
* @param {User} user The user that added the reaction
|
||||||
* @returns {?Snowflake|string}
|
* @returns {?Snowflake|string}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
collect(reaction) {
|
collect(reaction, user) {
|
||||||
/**
|
/**
|
||||||
* Emitted whenever a reaction is collected.
|
* Emitted whenever a reaction is collected.
|
||||||
* @event ReactionCollector#collect
|
* @event ReactionCollector#collect
|
||||||
@@ -92,6 +93,19 @@ class ReactionCollector extends Collector {
|
|||||||
* @param {User} user The user that added the reaction
|
* @param {User} user The user that added the reaction
|
||||||
*/
|
*/
|
||||||
if (reaction.message.id !== this.message.id) return null;
|
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);
|
return ReactionCollector.key(reaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
test/reactionCollectorCreated.test.js
Normal file
37
test/reactionCollectorCreated.test.js
Normal 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);
|
||||||
Reference in New Issue
Block a user