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?
Program Description & Purpose: When the bot goes online, every ten seconds, randomly select a random activity from the list of activities and update the bot with the new activity:
const activities = [
"with the &help command.",
"with the developers console.",
"with some code.",
"with JavaScript."
];
client.on("ready", () => {
// run every 10 seconds
setInterval(() => {
// generate random number between 0 and length of array.
const randomIndex = Math.floor(Math.random() * activities.length);
const newActivity = activities[randomIndex];
client.user.setActivity(newActivity);
}, 10_000);
});
Material to consider:
I changed it so you can change the status from playing to watching or listening.
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.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With