JavaScript
x
5
1
const backwardsFilter = (reaction, user) => reaction.emoji.name === '⏪' && user.id === message.author.id;
2
const forwardsFilter = (reaction, user) => reaction.emoji.name === '⏩' && user.id === message.author.id;
3
const backwards = msg.createReactionCollector(backwardsFilter, {time: 90000});
4
const forwards = msg.createReactionCollector(forwardsFilter, {time: 90000});
5
I tried to make one filter for both collectors but still have to type this (x,y,z) => filter(x,y,z,'⏪')
JavaScript
1
4
1
const filter = (reaction, user, c, emoji) => reaction.emoji.name === emoji && user.id === message.author.id;
2
const backwards = msg.createReactionCollector((x,y,z) => filter(x,y,z,'⏪'), {time: 90000});
3
const forwards = msg.createReactionCollector((x,y,z) => filter(x,y,z,'⏩'), {time: 90000});
4
Advertisement
Answer
You can make a higher-order function, one that takes in the character you’re looking for and returns a function that takes three arguments (reaction
, user
, and c
, corresponding to your current (x, y, x) =>
) and returns the appropriate filter operation.
Also, it doesn’t look like c
(same as z
) is being used at all in any code here, so feel free to remove it from the argument list.
JavaScript
1
4
1
const makeFilter = emoji => (reaction, user) => reaction.emoji.name === emoji && user.id === message.author.id;
2
const backwards = msg.createReactionCollector(makeFilter('⏪'), {time: 90000});
3
const forwards = msg.createReactionCollector(makeFilter('⏩'), {time: 90000});
4