DanGamingTV
DanGamingTV

Reputation: 45

How to set bot's status at different times of the day?

I have a discord bot and I'm trying to make the status change once every hour to bring some diversity. But I'm not really too familiar with javascript dates, any help? Here is my code:

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'})
}

Upvotes: 1

Views: 634

Answers (2)

DanGamingTV
DanGamingTV

Reputation: 45

Update: I eventually settled on an incremental timer.

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)
}

Upvotes: 1

Jonas Wilms
Jonas Wilms

Reputation: 138267

You could just check if the current hour is odd or even:

client.user.setActivity(
  quotes[(new Date).getHours() % 2], 
  {type: 'LISTENING'}
)

Or if you just want to randomly change every hour, use setInterval:

setInterval(() => {
  client.user.setActivity(
     quotes[Math.floor(quotes.length * Math.random())], 
      {type: 'LISTENING'}
  );
}, 1000 * 60 * 60);

Upvotes: 0

Related Questions