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

89
Visualizações
Discord.js bloquea a los usuarios con una identificación para que no usen ciertos comandos

Estoy tratando de hacerlo cuando la ID de usuario de alguien coincida con una variable, entonces reaccionará con ⛔. Esto funciona para todos mis otros comandos, pero cada vez que lo uso para este, reacciona con él, pero luego vamos a ejecutar el comando. ¿Algunas ideas? También a veces el mensaje se envía dos veces.

 client.on('message', async message => { // Check if the user who sent the message is in the list if ((message.author.id) === bannedid) { // If user is in list, then check if message matches a command if (message.content === 'hi') { await message.react('⛔'); } } else if (message.content === 'hi') { himessage(message); function himessage(message) { var messages = ['hi uwu', 'owo', 'no', 'stinky', 'amongus', 'The FitnessGram PACER Test is a multistage aerobic capacity test that progressively gets more difficult as it continues. The test is used to measure a students aerobic capacity as part of the FitnessGram assessment. Students run back and forth as many times as they can, each lap signaled by a beep sound. The test get progressively faster as it continues until the student reaches their max lap score. The PACER Test score is combined in the FitnessGram software with scores for muscular strength, endurance, flexibility and body composition to determine whether a student is in the Healthy Fitness Zone™ or the Needs Improvement Zone™.']; var cheese = Math.floor(Math.random() * messages.length) message.channel.send(messages[cheese]); } } });
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

EDITAR:

Para responder a su problema, la razón por la que su código sigue ejecutándose es porque su if(message.content === 'hi') y else if(message.content === 'hi') devolverán true .

Para evitar eso, puede detener la ejecución del código después de reaccionar:

 return message.react('⛔');

o modifique su sentencia else if :

 else if((message.author.id) != bannedid && message.content === 'hi') { // your code here. }

Este fue mi comentario original, donde entendí por error que su código no funcionaba, lo dejaré aquí ya que sigue siendo una forma viable de hacerlo:

Suponiendo que bannedid sea una matriz de ID, puede usar Array.prototype.some() para verificar todos los elementos de la matriz.

 if(bannedid.some(element => message.author.id === element) && message.content === 'hi') { // use return here so that the code will stop executing after reacting with the emoji. return message.react('⛔'); } else { // rest of your code }
about 4 years ago · Santiago Trujillo 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