#Error

1 messages ยท Page 1 of 1 (latest)

final field
slow mason
#

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()))
}

final field
#

here

#

ty

slow mason
#

alright

#

nono, i thank you, you're a legend

#

literally taking your time with my bullshit thhing

final field
#

no-no-no-no, you don't need .then

#

.then is like await

slow mason
#

so remove .then( and thats it?

final field
#

all .then's

#

member.forEach(m => array.push(m.user.username))

slow mason
#

oh god, you're a legend

#

may I ask something else as well?

final field
#

sure

slow mason
#

how am I able to do this but with just one role?

#

so users in a specific role

final field
#

if(m.user.roles.has(id)) {array.push(m.user.username)}

slow mason
#

member.forEach(m => if(m.user.roles.has(id)) {array.push(m.user.username)}) like this?

final field
#

Sure

#

id - your role id

slow mason
#

i can't do that tho

final field
#

It must be string

slow mason
#

"if" wont count

#

SyntaxError: Unexpected token 'if'

final field
#

Hm

tidal latch
#

Without them, it's meant to return something

final field
#

Oh

#

Yes

#

{if..}

#

Forgot about that

slow mason
#

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#

final field
#

Not uset

slow mason
#

user.roles.cache.has?

final field
#

User*

#

Member

slow mason
#

you guys are fucking legendary, thank you so much

#

can i also write the users in seperate lines with \n?

slow mason
#

so like
user1
user2

slow mason
#

and also, can i +rep you guys somewhere?

#

you're literally saving my life

tidal latch
slow mason
#

and i put that inside the if { ?

tidal latch
slow mason
#

i owe you so much

tidal latch
final field
slow mason
#

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?

tidal latch
slow mason
#
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

slow mason
#

honestly, I want to do it like this:

Memberlist:

@Role1:
- user1
- user2
@Role2:
- user1
- user2
#

i'm trying to do this exactly ^

slow mason
#

take your time ๐Ÿ™

tidal latch
#
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

slow mason
#

ReferenceError: roles is not defined

#

oh, i removed roles array

tidal latch
tidal latch
slow mason
tidal latch
slow mason
#

More than good, perfect. Thank you so much!

tidal latch
slow mason
#

But, why are the spaces there?

#

oh, i forgot to remove the tabs

tidal latch
slow mason
#

and to actually mention the roles, what do I do?

#

because simply @Founder wont work e.g

#

<@&${'roleid'}> ?

tidal latch
slow mason
#

can I replace 'roleid' with role1?

#

would that work?

tidal latch
#

You can also use Role#toString() which automatically does it for you, but you need to object

slow mason
#

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

tidal latch
slow mason
#

and how do I use it with this code?

tidal latch
slow mason
#

that would post the list every 24h?

final field
#

You need intervals

tidal latch
slow mason
#

I see

#

I'll try to do something and I'll get back if somethings wrong