#membercount as activity precence

55 messages · Page 1 of 1 (latest)

waxen talon
#

I want to take the Member count and put in inside my precence so people can see it in the activity

my current code:


module.exports = {
    name: 'ready',
    once: true,
    async execute(client) {

        setInterval(() => {
            let membersCount = client.guilds.cache.map(guild => guild.memberCount).reduce((a, b) => a + b, 0)

        }, 1000 * 60 * 5);
        const options = [
            {
                type: ActivityType.Playing,
                text: `mit [${membersCount} usern]`,
                status: "online"
            }
        ];
        await client.user.setPrecence({
            activities: [{
                name: [options].text,
                type: [options].type
                },
            ],
            status: [options].status
        }).catch(console.error);
    }
}```
Error: membersCount is not defined-
I'm not even sure if this whole code is right..
thin fractal
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

frail mantle
#

I would also set a bigger interval

waxen talon
#

i tried this

module.exports = {
    name: 'ready',
    once: true,
    async execute(client) {

        setInterval(async () => {
            let membersCount = client.guilds.cache.map(guild => guild.memberCount).reduce((a, b) => a + b, 0)
            const options = [
                {
                    type: ActivityType.Playing,
                    text: `mit [${membersCount} usern]`,
                    status: "online"
                }
            ];
            await client.user.setPrecence({
                activities: [{
                    name: [options].text,
                    type: [options].type
                },
                ],
                status: [options].status
            }).catch(console.error);
        }, 1000 * 60 * 10);


    }
}
#

still not showin

#

i feel like im doing something hella wrong

fast tinselBOT
#

guide Additional Information: Changes and deletions - ClientUser
read more

frail mantle
#

Nop

#

This is for v13, my bad

#

It's a Typo lol

fast tinselBOT
frail mantle
#

.setPresence not .setPrecence

waxen talon
#

not the solution, sadly

#

or do I have to wait this interval after starting?

frail mantle
#

You have to wait

#

You can assign the code inside the interval to its own function

#

And call it before and inside the interval

waxen talon
#

I did

 const memberCount = client.guilds.cache.map(guild => guild.memberCount).reduce((a, b) => a + b, 0)
        const options = [
            {
                type: ActivityType.Playing,
                text: `mit ${memberCount} usern`,
                status: "online"
            }
        ];
        await client.user.setPresence({
            activities: [{
                name: [options].text,
                type: [options].type
            },
            ],
            status: [options].status
        }).catch(console.error);
#

before the interval

#

And i get
TypeError [InvalidType]: Supplied activities[0].name is not a string.

waxen talon
#

I think its because its an Array in an Array

frail mantle
#

Why options is an array anyways?

#

Couldn't just be an object?

waxen talon
#
const memberCount = client.guilds.cache.map(guild => guild.memberCount).reduce((a, b) => a + b, 0)
        const options = 
            {
                type: ActivityType.Playing,
                text: `mit ${memberCount} usern`,
                status: "online"
            }
        await client.user.setPresence({
            activities: {
                name: [options].text,
                type: [options].type
            },
            status: [options].status
        })

No error anymore...
but no activiety still

spiral glen
#

what is [options].text supposed to do

spiral glen
waxen talon
#

You have a fix?

spiral glen
#

no, that is not what it does

waxen talon
#

Can you help me fix it then?

spiral glen
#

start by not making it into an array

waxen talon
#

so i delete the options const and just write in after the ":"?

spiral glen
#

what

#

do you know what [ 'a', 'b', 'c' ] is?

waxen talon
spiral glen
#

i mean, feel free to remove the object and write options directly, but that still won't change the fact that i'm asking if you even know what you did there

spiral glen
#

i can tell

waxen talon
#

i forgot it

#

tell me

spiral glen
#

...that you don't know

waxen talon
#

nice

#

do i even need it

spiral glen
#

the probably most basic part of javascript about "what is an array" and "what is an object and how do i access its properties"?

#

i think that's a yes

waxen talon
#

i think with those answers, i just get to know what i know so or so

#

I just started blindly
like many other programmers did

#

Dont tell me non stop that i dont know javascript basic.
This isnt helping a beginner at all

silk glacier
spiral glen
#

there are countless resources online for the latter

#

including #resources

#

what i will tell you is that activities should definitely be an array