问题
So, I am working on a discord bot. Here I start a reactionCollector
. When a reaction is collected, it does something, and when the reaction is removed, it should do something else.
await message.channel.send(embed)
then(async function (message) {
await message.react('⚔')
const filter = (reaction, user) => {
return reaction.emoji.name === '⚔' && user.id != 705462496646922311
};
collector = message.createReactionCollector(filter);
collector.on('collect', async (reaction, user) => {
// Do something.
});
collector.on('remove', (reaction, user) => {
// Do something.
});
})
.catch(function() {
message.channel.send('Error while adding the reaction. Try again')
});
The remove event never gets called. Does anyone know why this happen? Where did I do a mistake?
回答1:
To make your ReactionCollector fire dispose
and remove
events you have to enable dispose
in the CollectorOptions of your ReactionCollector just like that :
collector = message.createReactionCollector(filter, { dispose: true });
Also, be carefull when manipulating IDs (Snowflakes), they are always type of String. In your code you try to see if user.id
is not equal to a number (really big number by the way!) so don't forget to surround IDs with quotes.
return reaction.emoji.name === '⚔' && user.id != "705462496646922311";
来源:https://stackoverflow.com/questions/61858152/how-can-i-make-a-reactioncollector-on-a-remove-event-work