.setActivity not working for me

client.on('ready', () => {
client.user.setActivity('activity', { type: ActivityType.Watching });
console.log(`${client.user.tag} has logged on.`)
const channel = client.channels.cache.get('1234');
console.log(`${client.user.tag} Has succesfully connected to ${channel.guild.name} which has ${channel.guild.memberCount} active user(s).`);
});
client.on('ready', () => {
client.user.setActivity('activity', { type: ActivityType.Watching });
console.log(`${client.user.tag} has logged on.`)
const channel = client.channels.cache.get('1234');
console.log(`${client.user.tag} Has succesfully connected to ${channel.guild.name} which has ${channel.guild.memberCount} active user(s).`);
});
For some reason i am getting the error Cannot read properties of null (reading 'setActivity') even though i have used const { Client, GatewayIntentBits, ActivityType } = require('discord.js');
3 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Squink
Squink10mo ago
I fixed it thankfully, I forgot to remove a previous instance of the line client.user.setActivity('activity', { type: ActivityType.Watching }); so it was trying to execute before my bot was online as you just mentioned, everything is running as intended now thank you.