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

145
Vistas
Command that can work with and without tagging someone

I'm looking for a way to have a command which will give different responses depending on whether you have tagged someone along with the command.

Here's what I got so far:

module.exports = {
    name: 'attack',
    description: "uses attack embed",
    execute(message, args, Discord) {

var newEmbed = new Discord.MessageEmbed()
        .setColor('#A5775C')
        .setDescription(message.author.username + ' *attacked* '+ message.mentions.members.first().username);

var newEmbed1 = new Discord.MessageEmbed()
        .setColor('#A5775C')
        .setDescription(message.author.username + ' *attacked the enemy!*');

if (message.mentions.members.first()) {
       message.channel.send({embeds: [newEmbed]});
     }else{
       message.channel.send({embeds: [newEmbed1]});
     }
  }
} 

When I try this format, the command where you ping someone works, but when you don't ping someone, nothing happens.

Thanks for the help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Give this code a try it requires less code and will check for a target.

let target
if (message.mentions.members.first() === undefined) {
    target = 'the enemy.'
} else {
    target = message.mentions.members.first().username
}
const newEmbed = new Discord.MessageEmbed()
    .setColor('#A5775C')
    .setDescription(`${message.author} attacked ${target}`)

message.channel.send({
    embeds: [newEmbed]
})
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