简体   繁体   English

Discord.JS - 消息反应CPS测试

[英]Discord.JS - Message reaction CPS test

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?我有一个完全荒谬的问题,这可能是不可能的,但是 discord.js 机器人是否有可能发送消息,对其做出反应,然后检测您在一定时间内点击反应的速度有多快? Then it could send like "your cps is 10" or something?然后它可以发送像“你的cps是10”之类的?

If this is possible, I have no clue where to start, I just thought this would be cool.如果这是可能的,我不知道从哪里开始,我只是觉得这会很酷。 Please let me know!请告诉我!

It would be pretty inaccurate to create a CPS test in Discord through reactions.通过反应在 Discord 中创建 CPS 测试是非常不准确的。 There is a significant Discord-side delay when adding and removing reactions, and that delay is often unpredictable and variable (and it sometimes glitches).添加和删除反应时存在显着的 Discord 端延迟,并且该延迟通常是不可预测的和可变的(并且有时会出现故障)。 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.由于用户还必须单击以删除反应,因此您基本上必须将您收到的点击量乘以 2 来解释那些已删除的反应。 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.因此,一旦您将在某个时间跨度(例如 30 秒)内收到的所有点击加起来,并将点击总数乘以 2,您现在必须将该总数除以时间跨度。 So divide by 30 if you do 30 seconds.因此,如果您执行 30 秒,则除以 30。 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.如果是这种情况,请通过评论让我知道,我会修复答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM