Alanec
Alanec
DIAdiscord.js - Imagine an app
Created by Alanec on 2/2/2024 in #djs-questions
Detect bot removed reaction and return in messageReactionRemove
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
9 replies
DIAdiscord.js - Imagine an app
Created by Alanec on 2/2/2024 in #djs-questions
Detect bot removed reaction and return in messageReactionRemove
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
9 replies
DIAdiscord.js - Imagine an app
Created by Alanec on 2/2/2024 in #djs-questions
Detect bot removed reaction and return in messageReactionRemove
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
9 replies
DIAdiscord.js - Imagine an app
Created by Alanec on 2/2/2024 in #djs-questions
Detect bot removed reaction and return in messageReactionRemove
my inelegant solution is a global variable on the server...seems like the only way
9 replies
DIAdiscord.js - Imagine an app
Created by Alanec on 2/2/2024 in #djs-questions
Detect bot removed reaction and return in messageReactionRemove
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
9 replies