Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

65
Views
I want to set when someone mention me bot will respond

I'm trying to make my discord.js bot send messages when someone pings me. How can I do that??

I was trying with that code:

if(message.content === "<@723821826291138611>") {
message.channel.send("Hello, sup? ")
}

but that doesn't work. how can I do that?

7 months ago · Juan Pablo Isaza
2 answers
Answer question

0

The best - and most conventional - way to do this is to check the MessageMentions#(users|members) collection.

const { 
   mentions:{ 
      users,
      repliedUser
   }
} = message;

if (users.has("723821826291138611") && !repliedUser) {
   // Your code
}

This will return true if the mentioned is found in any order not only first, it's possible for the API to emit the mentions in different orders if multiple mentions were given. I wouldn't recommend searching the message.content string either.

7 months ago · Juan Pablo Isaza Report

0

You have to use if(message.content.includes("<@723821826291138611>")) instead of if(message.content === "<@723821826291138611>") to make it work!

But also you can use this code to do it:

let mentioned = message.mentions.members.first();
if(mentioned && mentioned.id == "723821826291138611") {
if(message.mentions.repliedUser) return;
message.channel.send("YOUR_TEXT")
}
7 months 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 job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.