#Error
1 messages ยท Page 1 of 1 (latest)
code: ```
if (cmd === 'members')
{
var array = []
const member = await message.guild.members.fetch()
.then(members => members.forEach(m => array.push(m.user.username)))
.then(message.channel.send(array.toString()))
}
alright
nono, i thank you, you're a legend
literally taking your time with my bullshit thhing
so remove .then( and thats it?
sure
if(m.user.roles.has(id)) {array.push(m.user.username)}
member.forEach(m => if(m.user.roles.has(id)) {array.push(m.user.username)}) like this?
i can't do that tho
It must be string
Hm
Surround in {}
Without them, it's meant to return something
TypeError: Cannot read properties of undefined (reading 'has')
at /home/accountcollecter/dh1bot.js:94:44
at Map.forEach (<anonymous>)
at Client.<anonymous> (/home/accountcollecter/dh1bot.js:94:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
root@ubuntu:/home/accountcollecter#
Not uset
user.roles.cache.has?
m.roles.cache.has
you guys are fucking legendary, thank you so much
can i also write the users in seperate lines with \n?
Yes
so like
user1
user2
and how am I able to do that?
and also, can i +rep you guys somewhere?
you're literally saving my life
array.join("\n") (instead of array.toString())
and i put that inside the if { ?
Edited my message
you guys are legendary.
i owe you so much
Lol the only thing I'd say would be my YT, but I don't want to self promo

i'll just cheeck your yt by myself
and, one more
if i make an array with role ids
and replace my role id
to list more people in more roles
i can do that right?
I don't understand that
Wdym
var roles = [ "918553941329981510", "909438213171609640" ]
var array = []
const member = await message.guild.members.fetch()
member.forEach(m => {if(m.roles.cache.has(roles)) {array.push(m.user.username)}})
message.channel.send(array.join("\n"))
like this
if I want to list the users in two roles
btw I have cleaner code
honestly, I want to do it like this:
Memberlist:
@Role1:
- user1
- user2
@Role2:
- user1
- user2
i'm trying to do this exactly ^
1 sec
take your time ๐
const members = await message.guild.members.fetch()
const role1 = members.filter(m => m.roles.cache.has(roles[0])),
role2 = members.filter(m => m.roles.cache.has(roles[1]))
message.channel.send(`@Role1
${[...role1.values()].join("\n")}
@Role2
${[...role2.values()].join("\n")}
`)
@slow mason tell me if this works
Whoops forgot template literal
Edited
Is it good?
More than good, perfect. Thank you so much!
๐
Ha
and to actually mention the roles, what do I do?
because simply @Founder wont work e.g
<@&${'roleid'}> ?
Exactly
It needs to be the role id
You can also use Role#toString() which automatically does it for you, but you need to object
I see, I'll just do it manually
and if I want this list to refresh every 24h i can just create an Interval function, right?
to edit it every 24h
if someone would get a role
Or you could use guildMemberUpdate event
and how do I use it with this code?
Put all the code in guildMemberUpdate event
that would post the list every 24h?
You need intervals
No, every time a member is updated (includes more changes like nicknames, so you gotta return if there are no role changes)