Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

742
Views
Discord.JS - Moving users in Discord to your VC using roles

I'm trying to move all users from a VC with a specific role, for example: !summon @role

With that, all users with that specific role should come to the VC where the user typed that command

At the moment my code looks like this:

else if (command === 'summon') {
                    const channel = message.member.voice.channel;
                    message.guild.members.cache.forEach(member => {
                        member.voice.setChannel(channel);
                    });
                    message.channel.send(`${message.author} users moved to your channel!`);
                }

At the moment i'm moving all users, however I only want users with the informed role

I tried to use:

                    message.mentions.roles.forEach(member => {
                        member.setChannel(channel);
                    });

But without success... can someone help me with this problem?

over 4 years ago ยท Santiago Trujillo
1 answers
Answer question

0

You can try replacing

message.guild.members.cache.forEach(member => {
    member.voice.setChannel(channel);
});

with

message.guild.members.cache.forEach(member => {
    if(member.roles.cache.has(message.mentions.roles.first()) {
        member.voice.setChannel(channel);
    }
}

Since member.roles.cache is a Collection it has a function .has. We take the first role mention from the message using message.mentions.roles.first() and check if it exists in the user's current roles using member.roles.cache.has(). If the user does have the first role mentioned in the message, the function returns true and we can move the to the specified channel. Hope this helps, don't forget about https://discord.js.org/#/docs for some documentation, can be quite useful ๐Ÿ˜….

over 4 years ago ยท Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!