Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda