0

I am creating a dump command, here is my code:

let role = message.mentions.roles.first() || message.guild.roles.cache.get(args[1]);

let oop = message.guild.members.cache.filter((member) => {
    return member.roles.cache.get(role.id);
  })
  .map((member) => {
    return member.user.tag;
  });

message.channel.send(`${oop.join("\n")}`);

I can't turn it on since my bot is verified and Discord won't approve my request because they won't grant intents just for 1 tiny command

I also know that you can fetch members using

guild.members.fetch()

But guild.members.fetch() Takes way longer than guild.members.cache So you will need to use await and/or .then()

I just don't know how to implement that to my code.

I am not sure if there is a way to do it, but if there is let me know :D.

Lioness100
  • 8,260
  • 6
  • 18
  • 49
Wide
  • 339
  • 2
  • 6
  • 18

1 Answers1

0

Basically

The is a shorter / easier way to get all members of a specific role:

message.guild.roles.cache.find(r => r.name === 'Name of your role').members.map(m => m.user.tag);

Alternatively, you can also use the ID of a role to retrieve it:

message.guild.roles.cache.get('your role Id').members.map(m => m.user.tag);

Both will return an array of user tags. Afterwards you can .join() this array to whatever format you want / need, e.g.:

const roleMemberList = message.guild.roles.cache.get('12345678910').members.map(m => m.user.tag).join('\n');

The output would look like this:

"Member1
 Member2
 Member3"

But...

According to the docs you are forced to enable the privileged intents in order to get users from cache. If Discord doesn't whitelist your bot, you might want to consider other use cases for the intents

So I guess you'll have to bite the bullet and use

guild.members.fetch()

until you get on the whitelist


Reference

Toasty
  • 1,850
  • 1
  • 6
  • 21