client.user.setActivity() doesnt work


#1

When I run client.user.setActivity() in the ready script on terminal on my computer it works, but all of a sudden on Glitch it says it’s not a function?


#2

Hi @GlitchMob04, welcome to the Glitch forum!

I’m moving this topic to the Discord Help category under the assumption that the client you mention is for a Discord bot. If that’s not the case let us know.

As far as your specific issue is concerned, seeing more of your code would be helpful. Ideally you’d share your project name so that folks to take a look.


#3

Yes, it’s a discord bot, and the code is quite simple, it just sets the bot’s ‘game’ when it starts, and here’s the code:

client.on("ready", () => {
  console.log(`Bot: Hosting ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`); 
  client.user.setActivity(`Use f!help.`);
});

And the error it gives me is that it’s not a function:

Bot: Hosting 34 users, in 40 channels of 1 guilds.
client.user.setActivity(`Use f!help.`);
^
TypeError: client.user.setActivity is not a function
at Client.client.on (/app/server.js:24:15)
at Client.emit (events.js:187:15)

MOD EDIT: formatting


#4

You can use this

client.on('ready', () => {
console.log('Bot: Hosting ' + `${client.users.size}` + ' users, in ' + `${client.channels.size}` + ' channels of ' + `${client.guilds.size}` + ' guilds.');
    client.user.setStatus('online')
    client.user.setPresence({
        game: {
            name: 'Use f!help',
            type: "Playing",
            url: "https://discordapp.com/"
        }
    });
});

MOD EDIT: formatting


#5

The following code should be the correct code. @PixelMania They had removed setPresence awhile back, so I do not think it would work unless he was using an earlier version!

client.on("ready", () => {
Use f!help.
client.user.setActivity(`Use f!help.`, {type: "playing"}); 
});

#6

PixelMania’s code worked, but for some reason it insists that setActivity isn’t a function.


#7

The current documentation seems to agree that setPresence is current and setActivity is no longer available.