Skip to content

Instantly share code, notes, and snippets.

@Lewdcario Lewdcario/raw-master.js Secret
Last active Jun 9, 2019

Embed
What would you like to do?
Raw event for master branch
// Taken from: https://raw.githubusercontent.com/discordjs/guide/master/code_samples/popular-topics/reactions/raw-event.js
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Ready!');
});
const events = {
MESSAGE_REACTION_ADD: 'messageReactionAdd',
MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
};
client.on('raw', async event => {
if (!events.hasOwnProperty(event.t)) return;
const { d: data } = event;
const user = client.users.get(data.user_id);
const channel = client.channels.get(data.channel_id) || await user.createDM();
if (channel.messages.has(data.message_id)) return;
const message = await channel.messages.fetch(data.message_id);
const emojiKey = data.emoji.id || data.emoji.name;
const reaction = message.reactions.get(emojiKey) || message.reactions.add(data);
client.emit(events[event.t], reaction, user);
if (message.reactions.size === 1) message.reactions.delete(emojiKey);
});
client.on('messageReactionAdd', (reaction, user) => {
console.log(`${user.username} reacted with "${reaction.emoji.name}".`);
});
client.on('messageReactionRemove', (reaction, user) => {
console.log(`${user.username} removed their "${reaction.emoji.name}" reaction.`);
});
client.login('your-token-goes-here');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.