Skip to content

Instantly share code, notes, and snippets.

@Danktuary
Last active May 18, 2018 05:23
Show Gist options
  • Save Danktuary/d38691d5a1765c1550be07632f406c4c to your computer and use it in GitHub Desktop.
Save Danktuary/d38691d5a1765c1550be07632f406c4c to your computer and use it in GitHub Desktop.
Reaction add count bug
const { Client } = require('discord.js');
const { token } = require('./config');
const client = new Client;
client.on('ready', () => console.log('Ready.'));
const events = {
MESSAGE_REACTION_ADD: 'messageReactionAdd',
MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
};
client.on('raw', async ({ t: eventName, d: data }) => {
if (!events.hasOwnProperty(eventName)) return;
const channel = client.channels.get(data.channel_id);
if (channel.messages.has(data.message_id)) return;
const user = client.users.get(data.user_id);
const message = await channel.messages.fetch(data.message_id);
const reaction = message.reactions.get(data.emoji.id || data.emoji.name);
client.emit(events[eventName], reaction, user);
});
client.on('messageReactionAdd', (reaction, user) => {
console.log('Reaction added; current count:', reaction.count);
});
client.on('messageReactionRemove', (reaction, user) => {
console.log('Reaction removed; current count:', reaction.count);
});
client.on('message', message => {
if (message.content === '!react') {
console.log('First reaction incoming.');
message.react('🤔');
}
});
client.login(token);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment