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

803
Views
(discord.js) ¿Cómo puedo hacer que este comando solo funcione para ciertos roles/usuarios?

Todavía soy bastante inepto en lo que respecta al desarrollo de software, y necesito ayuda para hacer que este comando funcione solo para ciertos roles en mi servidor de discordia, o solo para ciertos usuarios.

 client.on('message', async message => { if (message.content === '-fruits') { try { await message.react('🍎'); await message.react('🍊'); await message.react('🍇'); } catch (error) { console.error('One of the emojis failed to react:', error); } } });
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede restringir un comando a usuarios específicos creando una matriz de ID de usuario y, si el ID del autor del mensaje está en la lista, verifique si coincide con algún comando.

 // Create an array of user ids const adminIDs = [/* List of user IDs */] client.on('message', async message => { // Check if the user who sent the message is in the list if (adminIDs.include(message.author.id)) { // If user is in list, then check if message matches a command if (message.content === 'foo') { // do stuff... } else if (message.content === 'bar') { // do more stuff.. } } });

En cuanto a los roles, puede verificar si un usuario tiene un rol específico.

 client.on('message', async message => { // Check if the user has a role with the name "Admin" if (message.member.roles.find(r => r.name === 'Admin')){ if (message.content === 'foo') { // do stuff... } else if (message.content === 'bar') { // do more stuff.. } } });
over 4 years ago · Santiago Trujillo Report

0

Comenta la respuesta de @KyleRifqi (no tengo 50 repeticiones)

Los roles también tienen ID , por lo que puede hacer message.member.roles.find(r => r.id === "Role ID string") en su lugar, si tiene varios roles con el mismo nombre

over 4 years ago · Santiago Trujillo 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!