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

94
Vistas
I have a little problem with a certain command in discord.js

So I'm making a bot for myself to do stuff, and I tried to make a kill command

if (CMD_NAME == "kill") {
    let target = message.mentions.members.first()
    message.reply(`${target} is die`)
}

and I came to the conclusion that the bot doesn't know what is message.mentions.members.first() in general, how do I fix that? Also if I need to show more code, tell me

Edit: how I coded in the prefix:

    if (message.author.bot) return;
    if (message.content.startsWith(PREFIX)) {
        const [CMD_NAME, ...args] = message.content
        .trim()
        .substring(PREFIX.length)
        .split (/\/s+/)```
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Based on comments under your question, I think your problem might be somewhere else.

const PREFIX = "!"
let str = "!a b c"
const [CMD_NAME, ...args] = str.trim().substring(PREFIX.length).split(/\/s+/)
console.log(CMD_NAME)
console.log(args)

outputs:

a b c
[]

So it appears that your code is putting whole msg as "command name" which probably makes it fail name check and that's why nothing at all happens. Changing that split regex to /\s+/ to properly detect whitespaces changes the output to:

a
[ 'b', 'c' ]

which would probably fix your issue.

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