0
votes

I have a completely absurd question that is probably not possible, but would it be possible for a discord.js bot to send a message, react to it, and then detect how fast you can click the reaction in a certain amount of time? Then it could send like "your cps is 10" or something?

If this is possible, I have no clue where to start, I just thought this would be cool. Please let me know!

1
Yeah it's possible using a reaction collector - Pentium1080Ti
How could one do that? - user14897096
It is possible but it won't be accurate. - Jakye
lol its fine, i could possibly modify it if i have the code :> - user14897096
It would be pretty inaccurate even after modifying it. There is a significant Discord-side delay when adding and removing reactions, and that delay is often unpredictable and variable (and it sometimes glitches). Plus you would have to account for both the addition and removal of reactions since both are clicks, and both have those aforementioned delays. This is an insanely cool idea, but I'm pretty sure it wouldn't work that well. As for how to do it, look at reaction collectors on the docs. - Cannicide

1 Answers

1
votes

It would be pretty inaccurate to create a CPS test in Discord through reactions. There is a significant Discord-side delay when adding and removing reactions, and that delay is often unpredictable and variable (and it sometimes glitches). Plus you would have to account for both the addition and removal of reactions since both are clicks, and both have those aforementioned delays. This is an insanely cool idea, but I'm pretty sure it wouldn't work that well. As for how to do it, look at reaction collectors on the docs as I mentioned in my comment.

Note that, I'm pretty sure, reaction collectors only deal with adding reactions. Since the user also has to click to remove the reaction, you would basically have to multiply the amount of clicks you receive by 2 to account for those removed reactions. So once you add up all of the clicks you receive in a timespan such as 30 seconds and have multiplied the click total by 2, you now have to divide that total by the timespan. So divide by 30 if you do 30 seconds. And then you have the approximate clicks per second, though not quite accurate.

Here's a small, very simple (untested) example:

message.react('👌');

// Create a reaction collector
const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === message.author.id;

var clicks = 0; // (total clicks)
var timespan = 10; // (time in seconds to run the CPS test)

const collector = message.createReactionCollector(filter, { time: timespan * 1000 });

collector.on('collect', r => {
    console.log(`Collected a click on ${r.emoji.name}`);
    clicks++;
});

collector.on('end', collected => {
    console.log(`Collected ${clicks} raw clicks (adding reactions only)`);
    clicks *= 2;
    console.log(`Collected ${clicks} total approximate clicks.`);

    var cps = Math.round(clicks / timespan);
    console.log(`Your CPS averaged ~${cps} clicks per second over ${timespan} seconds.`);
});

I wrote this up very quickly without testing it to give you an idea of what you need to do, it may not work properly or I may have missed something. If that is the case, let me know through comments and I will fix the answer.