这是我更新状态的代码:
String[] status = new String[] {"Version: 1.5.0", "https://discord.gg/arWEM2h", "Love Backxtar", "You want me!", "Type: ~help", "User Counter: %members"};
int next = 60;
public void onSecond() {
if(next%5 == 0) {
if(!hasStarted) {
hasStarted = true;
StatChannelCommand.onStartUp();
}
Random rand = new Random();
int i = rand.nextInt(status.length);
shardMan.getShards().forEach(jda -> {
String text = status[i].replaceAll("%members", "" + jda.getUsers().size());
jda.getPresence().setActivity(Activity.playing(text));
});
StatChannelCommand.checkStats();
if(next == 0) {
next = 60;
}
}
else {
next--;
}
}
但是String
每秒钟运行一次。我以为是每5秒一次。我做了60秒%5。这段代码出了什么问题?
答案 0 :(得分:0)
首次输入方法onSecond()
时,条件next%5 == 0
将为true
。变量next
将不会更新,因为这仅发生在else
部分中。因此,方法next
的下一次运行仍将是60
。