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

167
Vistas
Agregar usuarios con rol al canal de subprocesos usando discord.js

Quiero agregar usuarios con un rol específico a los hilos. mi código es:

 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`); } } });

Pero cuando trato de usar este código me sale el 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.

¿Alguien puede decir cómo obtener la variable de canal? Obtengo el código de https://discordjs.guide/popular-topics/threads.html#adding-and-removing-members y no puedo encontrar el significado del canal.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Debe acceder a la propiedad del canal desde su objeto de message , por ejemplo:

 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