mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-31 08:00:07 +00:00
* add DMChannel#fetch() & Action#getChannel({recipients})
* ref for MessageReaction partial
* typings
* add PartialTypes.REACTION
* accommodate for fully removed reactions
* fix incorrect wording and typo
* typings: MessageReaction#count is nullable
* typings: mark MessageReaction#partial as readonly
Co-Authored-By: Vlad Frangu <kingdgrizzle@gmail.com>
* fix(User): fetch dm channel if cached one is partial
* docs: add missing comma
Co-Authored-By: Antonio Román <kyradiscord@gmail.com>
* fix: accomodate for new reactions
* fix: updating existing/new count on _patch
* docs: typo
* for consistency
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
'use strict';
|
||
|
||
const Action = require('./Action');
|
||
const { Events } = require('../../util/Constants');
|
||
const { PartialTypes } = require('../../util/Constants');
|
||
|
||
/*
|
||
{ user_id: 'id',
|
||
message_id: 'id',
|
||
emoji: { name: '<27>', id: null },
|
||
channel_id: 'id' } }
|
||
*/
|
||
|
||
class MessageReactionAdd extends Action {
|
||
handle(data) {
|
||
if (!data.emoji) return false;
|
||
|
||
const user = this.getUser(data);
|
||
if (!user) return false;
|
||
|
||
// Verify channel
|
||
const channel = this.getChannel(data);
|
||
if (!channel || channel.type === 'voice') return false;
|
||
|
||
// Verify message
|
||
const message = this.getMessage(data, channel);
|
||
if (!message) return false;
|
||
|
||
// Verify reaction
|
||
if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
|
||
const reaction = message.reactions.add({
|
||
emoji: data.emoji,
|
||
count: message.partial ? null : 0,
|
||
me: user.id === this.client.user.id,
|
||
});
|
||
if (!reaction) return false;
|
||
reaction._add(user);
|
||
/**
|
||
* Emitted whenever a reaction is added to a cached message.
|
||
* @event Client#messageReactionAdd
|
||
* @param {MessageReaction} messageReaction The reaction object
|
||
* @param {User} user The user that applied the guild or reaction emoji
|
||
*/
|
||
this.client.emit(Events.MESSAGE_REACTION_ADD, reaction, user);
|
||
|
||
return { message, reaction, user };
|
||
}
|
||
}
|
||
|
||
module.exports = MessageReactionAdd;
|