From 0edf46856a94bbaee73cd377cc04c01ca530f178 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sun, 28 Jan 2024 18:33:03 +0100 Subject: [PATCH] detect users adding/removing reactions --- events/reactionAdd.js | 6 ++++-- events/reactionRemove.js | 6 ++++-- index.js | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/events/reactionAdd.js b/events/reactionAdd.js index c45c021..35fc162 100644 --- a/events/reactionAdd.js +++ b/events/reactionAdd.js @@ -1,6 +1,8 @@ import { Events } from 'discord.js'; export const name = Events.MessageReactionAdd; -export async function execute(messageReaction, user) { - console.log(messageReaction, user); +export async function execute(reaction, user) { + const uname = user.username; + const rname = reaction._emoji.name; + console.debug(`[DEBUG] User '${uname}' reacted with emoji '${rname}'.`); } diff --git a/events/reactionRemove.js b/events/reactionRemove.js index 9fc1eaa..58d4c52 100644 --- a/events/reactionRemove.js +++ b/events/reactionRemove.js @@ -1,6 +1,8 @@ import { Events } from 'discord.js'; export const name = Events.MessageReactionRemove; -export async function execute(messageReaction, user) { - console.log(messageReaction, user); +export async function execute(reaction, user) { + const uname = user.username; + const rname = reaction._emoji.name; + console.debug(`[DEBUG] User '${uname}' removed reaction of emoji '${rname}'.`); } diff --git a/index.js b/index.js index 7112316..8b7aee2 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ import { fileURLToPath } from 'url'; import { promisify } from 'util'; import { config } from 'dotenv'; import { readdir } from 'fs'; +import { Partials } from 'discord.js'; config(); const readdirAsync = promisify(readdir); @@ -13,7 +14,14 @@ const optional = ['autocomplete', 'modalSubmit']; const runClient = (commands, events) => { // Create a new client instance - const client = new Client({ intents: [GatewayIntentBits.Guilds] }); + const client = new Client({ + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.GuildMessageReactions + ], + partials: [Partials.Message, Partials.Reaction] + }); client.commands = new Collection(); commands.forEach((c) => client.commands.set(c.data.name, c)); events.forEach((e) =>