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

121
Views
How do I check if the selected user in a slash command is a bot or not

So I'm making a discord bot which has a function to dm someone via slash command. Now how do i check if the user selected in the slash command is a bot or an actual user?

The slash command registerer

{
  'name': 'dm',
  'description': 'Dm someone if you are an admin',
  'type':1,
  "default_member_permissions": 'ADMINISTRATOR',
  'options': [
    {
      'name': 'user',
      'description': 'which user do you wanna dm?',
      'type': 6,
      'required': true
    },{
     'name': 'message',
     'description': 'The message you wanna send',
     'type':3,
     'required': true
    }
  ]
}

The logic

client.on('interactionCreate', (interaction) =>{
 if (!interaction.isChatInputCommand) return;
 if (interaction.commandName === 'apanker'){
   if (interaction.options.getSubcommand() === 'dm'){
     const message = interaction.options.getString('message')
     if (interaction.options.getUser('user') === interaction.user.bot) {
       interaction.reply(({ content: `Bots can't be`, ephemeral: true }))
       
     }
     else{
       const rec = interaction.options.getUser('user')
     const user = interaction.user.id
      try {
       rec.send({ embeds:[ new EmbedBuilder().setDescription(`<@${user}> says to you: ${message} `).setColor("#f05c51")
       .then(interaction.reply(({ content: 'Successfully sent', ephemeral: true })))

     ] })
      } catch (error) {
       interaction.reply(({ content: `Could not send message, maybe dm's off? -> ${error}`, ephemeral: true }))
      }
     }
   }
 }

})

But the if (interaction.options.getUser('user') === interaction.user.bot) does not work

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There is a .bot property which you may use to check if the user is a bot or not.

const user = interaction.options.getUser("user");
if (user.bot) {
  console.log("User is bot");
} else {
  console.log("User isn't bot")
};
almost 4 years ago · Santiago Trujillo 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!