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:
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?
After debugging a bit more I found the problem, so in case anyone runs into an issue here;
These do work, I just had an if statement that got in my way XD.
client.on('messageReactionAdd', (reaction, user) => {
console.log("added response");
});
client.on('messageReactionRemove', (reaction, user) => {
console.log("removed response");
});
In case they don't work, the message isn't cached. For which the following give a good starting point (I haven't fully tried them though):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.