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

166
Views
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 answers
Answer question

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 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!