Skip to content

Is there a way to make this code shorter? (reaction collector)

const backwardsFilter = (reaction, user) => === 'âª' && ===;
const forwardsFilter = (reaction, user) => === 'â©' && ===;
const backwards = msg.createReactionCollector(backwardsFilter, {time: 90000});
const forwards = msg.createReactionCollector(forwardsFilter, {time: 90000});

I tried to make one filter for both collectors but still have to type this (x,y,z) => filter(x,y,z,'âª')

const filter = (reaction, user, c, emoji) => === emoji && ===;
const backwards = msg.createReactionCollector((x,y,z) => filter(x,y,z,'âª'), {time: 90000});
const forwards = msg.createReactionCollector((x,y,z) => filter(x,y,z,'â©'), {time: 90000});


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.

const makeFilter = emoji => (reaction, user) => === emoji && ===;
const backwards = msg.createReactionCollector(makeFilter('âª'), {time: 90000});
const forwards = msg.createReactionCollector(makeFilter('â©'), {time: 90000});