如何以1秒的间隔从成员中删除角色? [英] How to remove roles from members with a 1 second interval?
问题描述
targets.forEach(member => member.roles.remove(role))
由于我担心会达到速率限制,是否可以以每位成员1秒的间隔删除该角色的方式来完成?我已经定义了角色"和目标".我已经完成了该项目,但不知道如何添加1秒的间隔.
Since I am worried about hitting the rate limit, can it be done in such a way that, the role is removed at an interval of 1 second per member? I've defined 'role' and 'targets'. I have completed the project, but couldn't figure out how to add the interval of 1 second.
推荐答案
在javascript中,您可以使用setInterval或setTimeout函数安排事件.
In javascript you can schedule events using the setInterval or setTimeout functions.
var index = 0;
var myInterval = setInterval(function() {
if (index < targets.length - 1)
targets[index].roles.remove(role);
else
clearInterval(myInterval);
index++;
}, 1000);
1000是循环运行之间的毫秒数.另外,我注意到您执行了role.remove,即使您的文字显示为添加.
The 1000 is the milliseconds between times the loop runs. Also I noticed you did roles.remove even though your text says add.
我意识到我忘了增加索引,所以我添加了它.
I realized I forgot to increment index so I added it.
这篇关于如何以1秒的间隔从成员中删除角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!