Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

739
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda