#how to message member count with a certain role? π
1 messages Β· Page 1 of 1 (latest)
Oh that seems easy
i told you noob
I'll get my code one sec
tyt
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
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β¦
message.guild.roles.get is not a function
Guild not defined
okay wait im try understand what u said. im an engineer i should get this
You have to specify a guild
client.guilds.fetch(id)
lol. never claimed i was a master at js buddy. im just asking for help. either be a nice person and help a noob, or go boost ur ego on someone please π
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?
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}`)
toocha
You use
```CODING LANGUAGE
CODE HERE
```
will try this
lol. whats coding language?
ive always wanted to be a coder
thats why i decided to do this
The programming language your coding in.
helping out a friend with their nft project
E.g js, json, java, etc
Let me give you a tip. The best way to learn programming is experience
ohhh nvm i get u now. we werent on the same page before lol.
Oh
I know why, you haven't passed through client through your execute() function
how do i pass?
Start Point: file.execute(message, args, client)
End Point: execute(message, args, client)
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
Change the 'countver' line to client.commands.get('countver').execute(message, args, client)
Cannot read properties
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 π
LOL
Try now.
this one?
remve the client from the execute starting point. correct?
Yes remove client from start point and end point
i didnt need to add the client because my guild was already defined right?
Ye
seee!! that other guy just came hating and flexing knowingg nothinnnn!!
Ye lol
Oh nice!
awesome π
π₯³
thank you broo i really appreciate ur time π
No problem
if u ever decided to get into nfts lmk, and ill airdrop yoou ur first piece for free βοΈ
likewise bro. hhit u a request
I accepted it
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
you should message.guild.members.fetch() before