Please describe the problem you are having in as much detail as possible:
When listening for messageReactionAdd (with raw emitter for the uncached message) console returns TypeError.
Include a reproducible code sample here, if possible:
// Case 1 using .emoji
client.on('messageReactionAdd', (messageReaction, user) => {
console.log(messageReaction.emoji.name)
});
/* TypeError: Cannot read property 'name' of undefined
at Client.client.on (C:\Users\viks\Desktop\basil\basil.js:79:36)
at Client.emit (events.js:198:13)
at reactionChannel.fetchMessage.then.msg (C:\Users\viks\Desktop\basil\basil.js:70:13)
at process._tickCallback (internal/process/next_tick.js:68:7) */
//-----------------------------------------------------------------------------------------
// Case 2 using ._emoji
client.on('messageReactionAdd', (messageReaction, user) => {
console.log(messageReaction._emoji.name)
});
/* TypeError: Cannot read property 'name' of undefined
at Client.client.on (C:\Users\viks\Desktop\basil\basil.js:79:37)
at Client.emit (events.js:198:13)
at reactionChannel.fetchMessage.then.msg (C:\Users\viks\Desktop\basil\basil.js:70:13)
at process._tickCallback (internal/process/next_tick.js:68:7) */
.last() I encounter this:client.on('messageReactionAdd', (messageReaction, user) => {
console.log(messageReaction.last()._emoji)
});
...to which console returns:
ReactionEmoji {
reaction:
MessageReaction {
message:
Message {
channel: [TextChannel],
deleted: false,
id: '589443774401216526',
type: 'DEFAULT',
content:
'he limpiado 5 mensajes por orden de: <@262388004675387393> �' ,
author: [ClientUser],
member: [GuildMember],
pinned: false,
tts: false,
nonce: undefined,
system: false,
embeds: [],
attachments: Collection [Map] {},
createdTimestamp: 1560604747153,
editedTimestamp: null,
reactions: [Collection],
mentions: [MessageMentions],
webhookID: null,
hit: null,
_edits: [] },
me: false,
count: 1,
users: Collection [Map] {},
_emoji: [Circular] },
name: '�',
id: null }
But gives a...
console.log(messageReaction.last()._emoji)
^
TypeError: messageReaction.last is not a function
...when using a custom emoji.
Case 2: custom emojis...
client.on('messageReactionAdd', (messageReaction, user) => {
console.log(messageReaction.last().emoji)
});
... to which console returns:
Emoji {
guild:
Guild {
members:
Collection [Map] {
'231217147869790208' => [GuildMember],
'246781870606516225' => [GuildMember],
'262388004675387393' => [GuildMember],
'325654156075335680' => [GuildMember],
'588289543162036246' => [GuildMember],
'588584416142426112' => [GuildMember] },
channels:
Collection [Map] {
'587404335961342082' => [VoiceChannel],
'587905715574800385' => [TextChannel],
'587915270052642816' => [TextChannel],
'588818158526136331' => [TextChannel],
'588893876870316053' => [TextChannel],
'588984749721124874' => [TextChannel],
'589383100874752010' => [CategoryChannel],
'589383117077348352' => [TextChannel],
'589383129324584970' => [TextChannel],
'589383140741480458' => [TextChannel] },
roles:
Collection [Map] {
'587404335281995786' => [Role],
'587825294644346883' => [Role],
'588289992678440960' => [Role],
'588712471028826125' => [Role],
'589383217447174144' => [Role],
'589383260396847124' => [Role],
'589383317732851712' => [Role] },
presences:
Collection [Map] {
'231217147869790208' => [Presence],
'262388004675387393' => [Presence],
'588289543162036246' => [Presence],
'588584416142426112' => [Presence] },
deleted: false,
available: true,
id: '587404335281995786',
name: 'Basil Dev',
icon: '8abc385497fa17230e7c8530ce4fb680',
splash: null,
region: 'eu-west',
memberCount: 6,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: null,
embedEnabled: undefined,
verificationLevel: 0,
explicitContentFilter: 0,
mfaLevel: 0,
joinedTimestamp: 1560329664145,
defaultMessageNotifications: 'MENTIONS',
ownerID: '262388004675387393',
_rawVoiceStates: Collection [Map] {},
emojis: Collection [Map] { '589413200735240195' => [Circular] } },
deleted: false,
id: '589413200735240195',
name: 'twitch',
requiresColons: true,
managed: false,
animated: false,
_roles: [] }
But gives a...
console.log(messageReaction.last().emoji)
^
TypeError: messageReaction.last is not a function
...when using stock unicode emojis.
Further details:
Several things
(with raw emitter for the uncached message)
If you are coming from the [guide], you should have seen the big warning there, stating that this is undocumented and _unsupported_. (If not, now you know)
In that case, you should rather open an issue there. (Although you should provide the exact code you use in your raw handler)
If this is your own implementation, I suggest to only use the raw event without messing with discord.js private api any further. (For example: Emit your own events using only the raw data, if that is works to you.)
This whole headache luckily gets fixed with [partials] on master / v12.
messageReaction._emoji
This is a private property you do neither have a reason to nor should use.
If you look at the source of MessageReaction#emoji, you see that the getter, in case of a ReactionEmoji, is checking for a newly available Emoji and falls back to _emoji if none was found.
This has nothing to do with your issue though.
messageReaction.last()
MessageReaction has no method called last.
It is representing a single reaction, not several.
Since this is working for you in same cases, I am going to suspect you emit something incorrect.
Thanks for the detailed answer. Yes, I was emitting something wrong indeed... my bad.
Most helpful comment
Several things
Firstly (and importantly in this issue)
If you are coming from the [guide], you should have seen the big warning there, stating that this is undocumented and _unsupported_. (If not, now you know)
In that case, you should rather open an issue there. (Although you should provide the exact code you use in your raw handler)
If this is your own implementation, I suggest to only use the raw event without messing with discord.js private api any further. (For example: Emit your own events using only the raw data, if that is works to you.)
This whole headache luckily gets fixed with [partials] on master / v12.
Secondly (and only as a note)
This is a private property you do neither have a reason to nor should use.
If you look at the source of
MessageReaction#emoji, you see that the getter, in case of a ReactionEmoji, is checking for a newly availableEmojiand falls back to_emojiif none was found.This has nothing to do with your issue though.
Lastly
MessageReactionhas no method calledlast.It is representing a single reaction, not several.
Since this is working for you in same cases, I am going to suspect you emit something incorrect.