如何使我的Discord机器人每10秒更改一次状态? [英] How do I make my Discord bot change status every 10 seconds?
本文介绍了如何使我的Discord机器人每10秒更改一次状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个smol Discord机器人(带有discord.js-commando),我有以下代码:
I have a smol Discord bot (with discord.js-commando), I have this code:
var activevar = ["with the &help command.", "with the developers console", "with some code", "with JavaScript"];
var activities = activevar[Math.floor(Math.random()*activevar.length)];
client.on('ready', () => {
client.user.setActivity(activities);
}
但是,只有当我重新启动机器人时,它才会改变.有人可以帮我吗?
But that only changes it when I restart the bot. Can someone help me out here?
推荐答案
针对v12上的用户进行了编辑,该版本现在使用bot而非客户端
Edited for users on v12 which now uses bot instead of client
const activities = [
"with the &help command.",
"with the developers console.",
"with some code.",
"with JavaScript."
];
bot.on("ready", () => {
// run every 10 seconds
setInterval(() => {
// generate random number between 1 and list length.
const randomIndex = Math.floor(Math.random() * (activities.length - 1) + 1);
const newActivity = activities[randomIndex];
bot.user.setActivity(newActivity);
}, 10000);
});
这篇关于如何使我的Discord机器人每10秒更改一次状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文