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

264
Views
Mi bot responde a todos los prefijos y no sé por qué

Estoy usando las últimas versiones de node.js y discord.js y estoy codificando en VSC. Mi bot comenzó a responder a todos los prefijos y no sé por qué. El código que tengo actualmente:

 const Discord = require('discord.js'); const client = new Discord.Client(); const fs = require('fs'); client.commands = new Discord.Collection(); const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); for(const file of commandFiles){ const command = require(`./commands/${file }`); client.commands.set(command.name, command) } const PREFIX = '$'; client.on('ready', () => { console.log('updated'); }) client.on('message', message => { const args = message.content.substring(PREFIX.length).split(" "); switch (args[0]) { case 'ping': message.channel.send('pong!'); break; } }); client.login(token);

Sin embargo, con este código en mente, el bot aún responde a cualquier prefijo. En la imagen a continuación, envié el comando ping con varias letras y símbolos aleatorios al mismo tiempo. El bot respondió pong a todos ellos.

Imagen del bot que no funciona

No estoy seguro de qué está mal, ya que todavía soy nuevo en discord.js, pero no puedo resolverlo.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tal vez puedas verificar si es un comando antes.

 client.on('message', message => { const isCommand = message.content.substring(0,PREFIX.length) === PREFIX if(isCommand){ const args = message.content.substring(PREFIX.length).split(" "); switch (args[0]) { case 'ping': message.channel.send('pong!'); break; } } });
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!