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

457
Views
¿Cómo hago que mi bot de discordia responda a un mensaje con prefijo?

Lo que estoy tratando de hacer es configurar un bot de respuesta automática de discordia que responda si alguien dice prefijo de coincidencia + objeto de respuesta como "! ping". No sé por qué no sale con ninguna respuesta en la disputa. Adjunto una imagen de lo que hace. No puedo entender por qué no aparece con ninguna respuesta en discordia.

 const Discord = require('discord.js'); const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]}); const prefix = '!' client.on('ready', () => { let botStatus = [ 'up!h or up!help', `${client.users.cache.size} citizens!`, `${client.guilds.cache.size} servers!` ] setInterval(function(){ let status = botStatus[Math.floor(Math.random() * botStatus.length)] client.user.setActivity(status, {type: 'WATCHING'}) }, 15000); console.log(client.user.username); }); client.on('message', message => { if(!message.content.startsWith(prefix) || message.author.bot) return const args = message.content.slice(prefix.length).split(/ +/) const command = args.shift().toLowerCase() const responseObject = { "ping": `🏓 Latency is ${msg.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms` }; if (responseObject[message.content]) { message.channel.send('Loading data...').then (async (msg) =>{ msg.delete() message.channel.send(responseObject[message.content]); }).catch(err => console.log(err.message)) } }); client.login(process.env.token);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su principal problema es que está tratando de verificar message.content contra 'ping' , pero requiere un prefijo. Su message.content siempre tendrá un prefijo, por lo que podría probar if (responseObject[message.content.slice(prefix.length)]) .

Otras alternativas serían agregar el prefijo al objeto ( "!ping": "Latency is..." )

O bien, cree una variable que rastree el comando utilizado.

 let cmd = message.content.toLowerCase().slice(prefix.length).split(/\s+/gm)[0] // then use it to check the object if (responseObject[cmd]) {}
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!