#how to message member count with a certain role? πŸ™

1 messages Β· Page 1 of 1 (latest)

final sun
charred mesa
#

Oh that seems easy

final sun
#

i told you noob

charred mesa
#

I'll get my code one sec

final sun
#

tyt

charred mesa
#

client.guilds.cache.get(guildId).members.cache.filter(m => m.roles.cache.some(r => r.id === id))

#

To get member count. Put .size at the end

final sun
#

why is this not working tho?

Just tryna understand

charred mesa
final sun
#

no

#

give me a sec ill tell ya the error

mellow forge
#

Because your two lines here aren’t related in any way. The first one used an undefined guild, the second doesn’t use what the first one calculated. Also you have some weird unnecessary brackets in place…

final sun
#

message.guild.roles.get is not a function

charred mesa
#

Guild not defined

final sun
#

okay wait im try understand what u said. im an engineer i should get this

charred mesa
#

You have to specify a guild
client.guilds.fetch(id)

final sun
#

define a guild as in point it to the server ID?

#

module.exports = {
name:'count',
description: 'count total members',
execute(message, args){
message.channel.send(${message.guild.memberCount});
}
}

#

cause this one woorked

#

but gave total members as i wanted

#

can i define a role froom there?

#

cause i think i defined the guild in the main.js

#

or is that not possible?

charred mesa
#

To fix your error. Delete everything inside execute function and paste this

const guildId = PUT GUILD ID HERE
const role = PUT ROLE ID HERE
const guild = client.guilds.fetch(guildId)
const memberCount = guild.members.cache.filter(m => m.roles.cache.some(r => r.id === role)).size

message.channel.send(`Member count: ${memberCount}`)
final sun
#

hw do i snippet the code like that?

#

sorry im really a noob at coode

charred mesa
#

You use
```CODING LANGUAGE
CODE HERE
```

final sun
#

will try this

#

lol. whats coding language?

#

ive always wanted to be a coder

#

thats why i decided to do this

charred mesa
#

The programming language your coding in.

final sun
#

helping out a friend with their nft project

charred mesa
#

E.g js, json, java, etc

#

Let me give you a tip. The best way to learn programming is experience

final sun
#

ohhh nvm i get u now. we werent on the same page before lol.

charred mesa
#

Lol

#

Does your code work?

final sun
#

will find oout in a sec

#

client not difned

#

defined*

#

:/

charred mesa
#

Oh

final sun
#

what do u propoose

#

const guild = client.guilds.fetch(950388442204889088)

#

this line

charred mesa
#

I know why, you haven't passed through client through your execute() function

final sun
#

how do i pass?

charred mesa
#

Start Point: file.execute(message, args, client)
End Point: execute(message, args, client)

final sun
#

gotcha

#
if(command === 'count') {
   client.commands.get('count').execute(message, args);
 }
    else if  (command === 'ping'){
      client.commands.get('ping').execute(message,  args);
     }
     else if  (command === 'countver'){
      client.commands.get('countver').execute(message,  args);
     }

});
#

this is how i have it at the start point

#

the js file is countver

charred mesa
#

Change the 'countver' line to client.commands.get('countver').execute(message, args, client)

final sun
#

soo was i correct?

#

was my guild identified?

charred mesa
#

... oh poop i just realised ._.

#

Using message can also get the guild

final sun
#

Cannot read properties

charred mesa
#

New code:

const role = PUT ROLE ID HERE
const memberCount = message.guild.cache.filter(m => m.roles.cache.some(r => r.id === role)).size
message.channel.send(`Member count: ${memberCount}`)
#

Forget anything I said about using client πŸ˜…

final sun
#

LOL

charred mesa
#

Try now.

charred mesa
#

Yes

#

If you added client where i told you to, remove it

final sun
#

remve the client from the execute starting point. correct?

charred mesa
#

Yes remove client from start point and end point

final sun
#

i didnt need to add the client because my guild was already defined right?

charred mesa
#

Ye

final sun
#

seee!! that other guy just came hating and flexing knowingg nothinnnn!!

charred mesa
#

Ye lol

final sun
#

@mellow forge sup

#

@charred mesa it worked!!

charred mesa
#

Oh nice!

final sun
#

awesome πŸ™‚

charred mesa
#

πŸ₯³

final sun
#

thank you broo i really appreciate ur time πŸ™

charred mesa
#

No problem

final sun
#

if u ever decided to get into nfts lmk, and ill airdrop yoou ur first piece for free ✌️

charred mesa
#

Ok

#

It was nice helping ya

final sun
#

likewise bro. hhit u a request

charred mesa
#

I accepted it

final sun
#

hey brozkii.

#

so to be honest with you lowkey last night the code didnt run but i was extremely tired to dig further intoo and u seemed like a high-energy guy so i just lied that it worked to hopefully please you, and it did lol

onyx hearth