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

168
Visualizações
Adding users with role to thread channel using discord.js

I want to add users with specific role to threads. My code is:

    bot.on('message', async message => {
  if (message.content == '?threadref') {    
    let list = message.guild.roles.cache.get('948258030192058410').members.map(m=>m.user.id);
    for (var i = 1; i < list.length; i++) {
      const user = list[i-1];
      const thread1 = channel.threads.cache.find(x => x.id === '945763756728787006');
      const thread2 = channel.threads.cache.find(x => x.id === '947100498035638283');
      const thread3 = channel.threads.cache.find(x => x.id === '947100722321846272');
      const thread4 = channel.threads.cache.find(x => x.id === '945763910756204585');
      const thread5 = channel.threads.cache.find(x => x.id === '946785089486987305');
      const thread6 = channel.threads.cache.find(x => x.id === '946784996537012254');
      const thread7 = channel.threads.cache.find(x => x.id === '946784810981023754');
      
      await thread1.members.add(user);
      await thread2.members.add(user);
      await thread3.members.add(user);
      await thread4.members.add(user);
      await thread5.members.add(user);
      await thread6.members.add(user);
      await thread7.members.add(user);
      console.log(`${user} was added to threads`);
    }
  }
});

But when i try to use this code i get error:

(node:453) UnhandledPromiseRejectionWarning: ReferenceError: channel is not defined
(node:453) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:453) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can someone tell how get channel variable. I get code from https://discordjs.guide/popular-topics/threads.html#adding-and-removing-members and there i can't find what channel mean.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to access the channel property from your message object, say:



  bot.on('messageCreate', async (message) => {
  let { channel } = message;
  if (message.content == '?threadref') { 
  ...   
}
});

/*
* Alternatively you can use message.channel 
 directly on each time you a define thread. 
* Welcome to stackoverflow! 😄
*/


about 4 years ago · Juan Pablo Isaza 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