Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda