我有一个smol Discord机器人(带有discord.js-commando),我有这个代码:
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);
}但这只会在我重启机器人时改变它。有人能帮帮我吗?
发布于 2018-07-10 22:50:22
为v12上的用户编辑,它现在使用bot而不是客户端
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);
});发布于 2021-01-14 18:33:23
我更改了它,以便您可以将状态从播放更改为正在观看或正在收听。
const activities_list = [
"For Rule Breakers",
"The purple names",
"#general",
"The mods do their job"
]; // creates an arraylist containing phrases you want your bot to switch through.
client.on('ready', () => {
setInterval(() => {
const index = Math.floor(Math.random() * (activities_list.length - 1) + 1); // generates a random number between 1 and the length of the activities array list (in this case 5).
client.user.setActivity(activities_list[index], { type: 'WATCHING' }); // sets bot's activities to one of the phrases in the arraylist.
}, 10000); // Runs this every 10 seconds.
});发布于 2021-07-02 09:54:47
考虑到这篇文章的浏览频率,我想我应该提供一个更新更清晰的回复。
const state = 0;
const presences = [
{ type: 'PLAYING', message: 'a game' },
{ type: 'WATCHING', message: 'a video' }
];
setInterval(() => {
state = (state + 1) % presences.length;
const presence = presences[state];
client.user.setActivity(presence.message, { type: presence.type });
}, 10000);https://stackoverflow.com/questions/51180927
复制相似问题