Detect bot removed reaction and return in messageReactionRemove

Node: 20.8.0 discordjs: 14.14.1 I think i'm losing my mind. I swear at one point the following was true:
await reaction.users.remove(fullUser);
await reaction.users.remove(fullUser);
removed a users reaction. This is still true. But then i used to be able to detect in the Events.MessageReactionRemove if the bot was the one who removed the reaction and return early. I must be going crazy though because nothing works.
client.on(Events.MessageReactionRemove, async (reaction, user) => {
if (user.id === user.client.user.id) {
return;
}
if (user.bot) {
return;
}
client.on(Events.MessageReactionRemove, async (reaction, user) => {
if (user.id === user.client.user.id) {
return;
}
if (user.bot) {
return;
}
The user is always the user who reaction initially, not the one removing. Maybe this has always been the case and there is no solution to my problem. I just need to know one way or another if it's possible or ever was possible.
5 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna8mo ago
this has always been the case
Alanec
Alanec8mo ago
Ah okay thank you. Is there an elegant solution to accomplishing my goal that's used by the community? I can't be the first one to want to solve this problem
treble/luna
treble/luna8mo ago
I dont think so as there's no audit log event afaik
Alanec
Alanec8mo ago
my inelegant solution is a global variable on the server...seems like the only way
interface ReactionInfo {
originalUserId: string;
reaction: string;
}

const reactionsRemovedByBot: Record<string, ReactionInfo> = {};

//onreaction add
// reaction add, validation fail
const fullUser = await user.fetch();

reactionsRemovedByBot[reaction.message.id] = {
originalUserId: fullUser.id,
reaction: reaction.emoji.name ?? ''
};

// this is triggering the MessageReactionRemove event.
await reaction.users.remove(fullUser);
return;

//on reactionRemove
const botReactionRemoval = reactionsRemovedByBot[reaction.message.id];
if (
botReactionRemoval &&
user.id === botReactionRemoval.originalUserId &&
botReactionRemoval.reaction === reaction.emoji.name
) {
console.log('im the bot');
// Clear the flag and return early if the bot removed the reaction programmatically
delete reactionsRemovedByBot[reaction.message.id];
return;
}
interface ReactionInfo {
originalUserId: string;
reaction: string;
}

const reactionsRemovedByBot: Record<string, ReactionInfo> = {};

//onreaction add
// reaction add, validation fail
const fullUser = await user.fetch();

reactionsRemovedByBot[reaction.message.id] = {
originalUserId: fullUser.id,
reaction: reaction.emoji.name ?? ''
};

// this is triggering the MessageReactionRemove event.
await reaction.users.remove(fullUser);
return;

//on reactionRemove
const botReactionRemoval = reactionsRemovedByBot[reaction.message.id];
if (
botReactionRemoval &&
user.id === botReactionRemoval.originalUserId &&
botReactionRemoval.reaction === reaction.emoji.name
) {
console.log('im the bot');
// Clear the flag and return early if the bot removed the reaction programmatically
delete reactionsRemovedByBot[reaction.message.id];
return;
}
here's what i came up with In case anyone comes across this thread: That code stores a reaction removal from a bot keyed by the message ID and saves the originalUserID who's reaction we removed and the reaction name. Then we can lookup on reaction removal if the bot removed a reaction for that message, and then check that the User param (which SHOULD be the bot but is the user instead) matches the user id in that bot removal Record. If it does, it was actually removed by the bot and we can return You're right, I was wrong to say what that parameter should do, it's working as expected for sure. It would be nice for that to be exposed though, somehow
Want results from more Discord servers?
Add your server