Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

459
Vistas
How do i make my discord bot respond to a message with prefix?

What I'm trying to do is set up a discord autoresponse bot that responds if someone says match prefix + respondobject like "!ping". I don't know why it doesn't come up with any response in the dispute. I've attached a picture of what it does. I can't figure out why it's not showing up with any responses in discord.

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 Respuestas
Responde la pregunta

0

Your main issue is that you're trying to check message.content against 'ping', but require a prefix. Your message.content will always have a prefix, so you could try if (responseObject[message.content.slice(prefix.length)]).

Other alternatives would be to add the prefix to the object ("!ping": "Latency is...")

Or, create a variable that tracks the command used.

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda