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

148
Views
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 answers
Answer question

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 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!