I've created a system which allows users to send a poll in a channel and want to give them extra options in a private message. For this, I'm trying to toggle a poll option when the user reacts to this private message with an emoji. The server part works perfectly fine, but I can't get the private message reactions to work as intended.
In summary: I'm trying to do something when the user reacts to a private message with an emoji. I've got this working perfectly fine for server channels.
To test this I've tried the following:
This first one doesn't seem to get called with private messages.
client.on('messageReactionAdd', (reaction, user) => {
console.log("added response");
});
client.on('messageReactionRemove', (reaction, user) => {
console.log("removed response");
});
This second one is test code that runs in response to the "!beep" command. Yet shows a few problems:
- The filter never passes and "collected" never gets logged.
- The filter only works after the reactions are added (I assume it's because of the async, but I want users to be able to toggle the option whenever they press on the reaction)
- The code doesn't get triggered when a reaction is removed (I assume this is because awaitReactions doesn't support that, but I want users to be able to toggle the option whenever they press on the reaction, regardless of whether they are adding or removing it)
- I tried removing the error bit, which logs "collected" after the time's up. But I want it to be responsive, and thus instant, and I also want it to be reusable so users can toggle it on and off.
const reactions = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "????"];
message.channel.send('@here Boop :robot:')
.then(async (sentMessage) => {
for (var i=0; i < reactions.length; i++) {
await sentMessage.react(reactions[i]);
}
/////////////// TEST CODE!!!!
const filter = (reaction, user) => {
console.log("filter called");
return true;
};
sentMessage.awaitReactions(filter, { time: 33000, errors: ['time'] })
.then(collected => {
console.log("collected");
const reaction = collected.first();
console.log(reaction.emoji);
})
.catch(collected => {
console.log("Time's up");
});
});;
TLDR: I want to give a poll config panel to a user in a private message, that allows said user to toggle an option by clicking on a reaction to said config panel.
The stuff I tried didn't work. Am I doing something wrong? Is there some other way to do this? Or is this simply not possible?