Discord.js bot update activity

I wanted to create an updating status with all kind of activity on my BOT. This is the code of what I have done so far:

const activities = [
            type : "PLAYING",
            activity : "with the ball"
            type : "WATCHING",
            activity : "your soul"

    for (var i = 0; i < activities.length; i++) {
        setInterval(() => client.user.setActivity(`${activities[i].activity}`, { type: `${activities[i].type}` }));

When I try to start the BOT, the terminal shows

TypeError: Cannot read property ‘activity’ of undefined

Probably the code is totally wrong, but I’m not very good at javascript. Any suggestions?

10 thoughts on “Discord.js bot update activity”

  1. the setInterval will force an async operation, but the stack value works only in the loop context. You can create another variable first, javascripts Garbage Collector will notice "oh i can’t clean up this, i need it later", so javascript still have this value in his stack

    for (var i = 0; i < activities.length; i++) {
        const putonstack = activities[i];
        setInterval(() => client.user.setActivity(`${putonstack.activity}`, { type: `${putonstack.type}` }));

Leave a Comment