Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

66
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos