我有一个不和谐的机器人,我试图每小时进行一次状态更改,以带来一些多样性。但是我对JavaScript日期不是很熟悉,有帮助吗? 这是我的代码:
var quotes = ["to my fire mix | >commands", "to youtube videos | >commands"]
if(it is this time of day){
var rand = quotes[Math.floor(Math.random() * quotes.length)];
client.user.setActivity(rand, {type: 'LISTENING'})
}
答案 0 :(得分:1)
更新: 我最终选择了增量计时器。
function refreshStatus(){
var quotes = ["my fire mix | >commands", "youtube videos | >commands", "the loneley sound of nothing | >commands", "audiomemes memes | >commands", "danno | >commands"]
x = 5
x=x*60
rand = quotes[Math.floor(quotes.length * Math.random())]
if(rand){
client.user.setActivity(rand, {type: 'LISTENING'});
}
setTimeout(refreshStatus, x*1000)
}
答案 1 :(得分:0)
您只需检查当前时间是奇数还是偶数:
client.user.setActivity(
quotes[(new Date).getHours() % 2],
{type: 'LISTENING'}
)
或者,如果您只想每小时随机更改,请使用setInterval:
setInterval(() => {
client.user.setActivity(
quotes[Math.floor(quotes.length * Math.random())],
{type: 'LISTENING'}
);
}, 1000 * 60 * 60);