Discord.js: Cannot read property ‘setActivity’ of undefined

I’m wondering why setActivity seems to go undefined. I’ve set up an Event Handler which works perfectly fine for my ‘message’ and ‘ready’ event. But as soon as I added this line of code to my ‘ready’ event to give my bot a custom status it for some reason does not work and I am unsure why. Since I don’t know if it’s to do with my Event Handler or ‘ready’ event I will show both files below. 🙂

Event Handler:

const fs = require('fs');

module.exports = (client, Discord) => {
    const load_dir = (dirs) => {
        const eventFiles = fs.readdirSync(`./Natsuki Events/${dirs}`).filter(file => file.endsWith('.js'));

        for (const file of eventFiles) {
            const event = require(`../Natsuki Events/${dirs}/${file}`);
            const eventName = file.split('.')[0];
            client.on(eventName, event.bind(null, Discord, client))
        }
    }

    ['Client', 'Guild'].forEach(e => load_dir(e));
}

‘ready’ event:

module.exports = (client) => {
    console.log('Natsuki is online!');
    client.user.setActivity("A game with That Penguin Guy || Type 'n! help'");
}

Answer

You should set the activity of your bot in its constructor, not in the ready event to make sure that the bot can go online with the correct information and to avoid issues with other timings.

const { Client } = require("discord.js");

const client = new Client({
  /* Your other options like intents */
  presence: {
    activities: [{
      type: 0,
      name: "A game with That Penguin Guy || Type 'n! help'"
    }],
  },
});

Relevant Discord.JS docs:

Relevant Discord docs: